Search json for key value and display the associated values

Greetings; I am new to AppInventor. i am developing an app where i receive JSON from file content. i want to be able to search for the first occurrence of a keyword and display it associated values in a label. example below is my json. i want to use a text box to search for where keyword is equal to FBL for the key "code" and when found display branch, id, name, code and status values in a label.

{
"bankDtos": [
{
"branch": null,
"id": 1,
"name": "Zenith",
"code": "ZVA",
"status": 0,
"rowNumber": 0
},
{
"branch": null,
"id": 2,
"name": "Commercial Bank",
"code": "GCB",
"status": 0,
"rowNumber": 0
},
{
"branch": null,
"id": 3,
"name": "Fidelity",
"code": "FBL",
"status": 0,
"rowNumber": 0
},
{
"branch": null,
"id": 4,
"name": "Universal Merchant ",
"code": "UMB",
"status": 0,
"rowNumber": 0
},
{
"branch": null,
"id": 5,
"name": "Republic ",
"code": "RBL",
"status": 0,
"rowNumber": 0
},
{
"branch": null,
"id": 6,
"name": "Technical",
"code": "TEC",
"status": 0,
"rowNumber": 0
}
]
}


dict_finder.aia (2.6 KB)




P.S. These blocks can be dragged directly into your Blocks Editor workspace.

Dragging blocks

1 Like

@ABG thank you.
Now i want to use the phone camera to scan a qrcode or barcode from an ID card to get the input code such as FBL to search for the code. so a button is clicked to scan code the back camera will open and scan the card and pick the code from the barcode and search automatically to get the result.

I have not used the scanner component myself.

I recommend copying the scanner result to a Label to make sure it makes sense before proceeding.

Let us know how it works for you,

P.S. Here's a starter kit for you to play with:



dict_finder.aia (3.3 KB)

1 Like

@ABG . Thank you .

@ABG Please, one final thing. Instead of showing the result in ListView, I want to use labels tob represent the result. so I get the value for the keys in the label for Branch, Code, and Name.

So Branch and Name depend uniquely on Code?

Yes.. Code is Unique. All code have branch and Name

This becomes simpler, then.




when  btnScan .Click do





dict_finder.aia (3.4 KB)

1 Like

@ABG Thank you for your support. it is working like magic ..lolx

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.