How to iterate through JSON results and display

I am having difficulty coding for a variable number of results to be returned and displayed on a screen. The code works to return item 1 (without the for each item loop), but when I add that block and the display of the app_variable_ListofNames, I get nothing or a ‘,’ when there are multiple results. I tried swapping out to a list viewer control, but that didn’t work for me either.

Here is the code:

and here is an example of the JSON output it reads:

{
“normalizedInput”: {
“line1”: “”,
“city”: “Eden Prairie”,
“state”: “MN”,
“zip”: “55347”
},
“kind”: “civicinfo#representativeInfoResponse”,
“divisions”: {
“ocd-division/country:us/state:mn”: {
“name”: “Minnesota”,
“officeIndices”: [
0
]
}
},
“offices”: [
{
“name”: “U.S. Senator”,
“divisionId”: “ocd-division/country:us/state:mn”,
“levels”: [
“country”
],
“roles”: [
“legislatorUpperBody”
],
“officialIndices”: [
0,
1
]
}
],
“officials”: [
{
“name”: “Amy Klobuchar”,
“address”: [
{
“line1”: “425 Dirksen Senate Office Building”,
“city”: “Washington”,
“state”: “DC”,
“zip”: “20510”
}
],
“party”: “Democratic Party”,
“phones”: [
“(202) 224-3244”
],
“urls”: [
https://www.klobuchar.senate.gov/
],
“photoUrl”: “http://bioguide.congress.gov/bioguide/photo/K/K000367.jpg”,
“channels”: [
{
“type”: “Facebook”,
“id”: “amyklobuchar”
},
{
“type”: “Twitter”,
“id”: “amyklobuchar”
}
]
},
{
“name”: “Tina Smith”,
“address”: [
{
“line1”: “720 Hart Senate Office Building”,
“city”: “Washington”,
“state”: “DC”,
“zip”: “20510”
}
],
“party”: “Democratic Party”,
“phones”: [
“(202) 224-5641”
],
“urls”: [
https://www.smith.senate.gov/
],
“photoUrl”: “https://mn.gov/governor/assets/press_smith-2015_tcm1055-154819.jpg”,
“channels”: [
{
“type”: “Facebook”,
“id”: “USSenTinaSmith”
},
{
“type”: “Twitter”,
“id”: “SenTinaSmith”
}
]
}
]
}

1 Like

Check this

Thank you, @muneer! Your solution worked for me.

1 Like