API results into a List Viewer

@Mark,

Thanks for your response. I got it working now!

The issue is the 'get object from JSON' block will not connect to the 'for each item j in list' block as depicted here:
Not%20Connecting

However if I save the 'get object from JSON - response' block in a list variable 1st, I am then able to connect the variable to the 'for each item j in list' block. Glad to have this working, and I’ve added my final solution below.

Thanks,
Darren


The following shows how to loop through a JSON List that is returned through an API response.
Multiple%20Objects%20Working

3 Likes

Darren,

I’m glad its working now! And I’ve reported the bug that you found whereby you couldn’t connect the 'get object from JSON' block to the 'for each item j in list' block.

-Mark

1 Like

WHere do you find the “Get” block with the “Response” in it? I only see Value and Error when I pull from the Realtime component.

The 'get object from JSON' block is in the Object drawer. You would plug the Value block in to that to create an object from the JSON response.

-Mark

Thanks @Mark. I was referring to the “In OpenBrewery” call block.

Sorry, I meant to say that you would plug the response block (from your 'In OpenBreweryDB get' call) into the 'get object from JSON' block.

Hi @Mark. I followed the blocks above but parsing the db does not seem to work. Here are my blocks for pull the data for my ToDo list. It seems to save it to the db just fine. but will not display it in the listview. Also, since the data does not seem to be writing to my variable, it gets over-written when I exist the screen (this is when the list is saved to the DB. Any suggestions would be very appreciated.


1 Like

I have been trying this today with no luck as well.

Following

Something like this? I believe the issue you are facing is something like one I had.

Hey , tried to do what you suggested here but with no luck unfortunately .
Here is my data (Would be very thankful for any one who can help ) :
“results”: [

    {

        "business_status": "OPERATIONAL",

        "geometry": {

            "location": {

                "lat": 32.4747588,

                "lng": 34.9713922

            },

            "viewport": {

                "northeast": {

                    "lat": 32.4760607302915,

                    "lng": 34.9726427302915

                },

                "southwest": {

                    "lat": 32.4733627697085,

                    "lng": 34.9699447697085

                }

            }

        },

        "icon": "https://maps.gstatic.com/mapfiles/place_api/icons/v1/png_71/generic_business-71.png",

        "name": "Central Veterinary pets Pardes Hanna",

        "opening_hours": {

            "open_now": false

        },

        "photos": [

            {

                "height": 4160,

                "html_attributions": [

                    "<a href=\"https://maps.google.com/maps/contrib/114373861275704723265\">יערה בקר</a>"

                ],

                "photo_reference": "ATtYBwLb1k7mSuRy6mMRGcWuDkEvxXrvDGopTHGb7gC_bQcg6bYxlElEDh3Enl3uVDAmkOGCbn_MZuaXM5SC10qSMM_pOgcbyAwyudhqs2VrmDlUS-Ux6PxhQQZsXSZ5Z-0HDeRgV0SfIrRIbDwgr1amVbiWGzSG7e0VzV9K1qiNr-6D1oK-",

                "width": 3120

            }

        ],

        "place_id": "ChIJ8eHKNNUIHRUR6Ce4t9iy8YY",

        "plus_code": {

            "compound_code": "FXFC+WH Pardes Hanna-Karkur, Israel",

            "global_code": "8G4PFXFC+WH"

        },

        "rating": 4.8,

        "reference": "ChIJ8eHKNNUIHRUR6Ce4t9iy8YY",

        "scope": "GOOGLE",

        "types": [

            "veterinary_care",

            "point_of_interest",

            "establishment"

        ],

        "user_ratings_total": 147,

        "vicinity": "HaOranim Street 18, Pardes Hanna-Karkur"

    },

    {

        "business_status": "OPERATIONAL",

        "geometry": {

            "location": {

                "lat": 32.471729,

                "lng": 34.973782

            },

            "viewport": {

                "northeast": {

                    "lat": 32.4730747802915,

                    "lng": 34.97513418029149

                },

                "southwest": {

                    "lat": 32.4703768197085,

                    "lng": 34.9724362197085

                }

            }

        },

        "icon": "https://maps.gstatic.com/mapfiles/place_api/icons/v1/png_71/generic_business-71.png",

        "name": "ד\"ר תמר וטרינרית",

        "opening_hours": {

            "open_now": true

        },

        "photos": [

            {

                "height": 2500,

                "html_attributions": [

                    "<a href=\"https://maps.google.com/maps/contrib/113764155770280100997\">ד&quot;ר תמר וטרינרית</a>"

                ],

                "photo_reference": "ATtYBwLRR-1lw5O3rpFEKRTQuDW_o8TfnM3E7I2q23BtZe5sA-MBN0YmiCYLCgRKPJEzhofawhBFCY8hunKw3kobocr0rFLZHKzwn2HVNBIq_LqyssXwX2Vih3zn8kwvZ0-5FB3lntfJlSEmfhc_TZLO4TN5bQsZ7SNFuOKfTVNP8TwViCtF",

                "width": 3750

            }

        ],

        "place_id": "ChIJucOIFTwOHRURXGwQdE1jWRU",

        "plus_code": {

            "compound_code": "FXCF+MG Pardes Hanna-Karkur, Israel",

            "global_code": "8G4PFXCF+MG"

        },

        "rating": 4.8,

        "reference": "ChIJucOIFTwOHRURXGwQdE1jWRU",

        "scope": "GOOGLE",

        "types": [

            "veterinary_care",

            "health",

            "point_of_interest",

            "establishment"

        ],

        "user_ratings_total": 16,

        "vicinity": "העצמאות 8 פרדס חנה כרכור"

    },

@alexey.ben Which data item(s) are you wanting to get from that JSON response?

@tatiang I`m sorry , forgot to explain my self.
I actually want to get a list of “lat” property .
I know how to get a specific lat property inside the (for example #2 index) but I want it to run and get a list with “lat” propertys .

I can help you create a loop to do that. What do your blocks look like that work to get a single lat property?

1 Like

Based on the blocks you sent me, it looks like your JSON response is just an array/list of businesses at the top level. So you should be able to use a “for each i in list [get property ‘results’ of object [get object from JSON [app response]]]” block and replace the “1” with i. The “for each” block would go around the entire function contents except the return block. You’d need to store the value you get in a list within the loop, using the “insert in list [app listviewer data] as last […the entire set of function blocks except the return block]”. Then, use the “app listviewer” as the value for your list viewer text items.

Try that and if you need a screenshot of the blocks, I can make that for you.

3 Likes

kindly , if you can please add a screenshot with the blocks (want to be sure i did the right thing)

1 Like

@alexey.ben Try this:

If that doesn’t work, can you post the full JSON response? It was a little hard to work with the partial response you posted but I think I have it right.

1 Like

Thank you for your attempt to help but unfortunately its still doesnt work and for some reason the app crashes every time when i try to run those blocks.
Any way , the full response as you asked me to is :
{

"html_attributions": [],

"results": [

    {

        "business_status": "OPERATIONAL",

        "geometry": {

            "location": {

                "lat": 32.4747588,

                "lng": 34.9713922

            },

            "viewport": {

                "northeast": {

                    "lat": 32.4760607302915,

                    "lng": 34.9726427302915

                },

                "southwest": {

                    "lat": 32.4733627697085,

                    "lng": 34.9699447697085

                }

            }

        },

        "icon": "https://maps.gstatic.com/mapfiles/place_api/icons/v1/png_71/generic_business-71.png",

        "name": "Central Veterinary pets Pardes Hanna",

        "opening_hours": {

            "open_now": true

        },

        "photos": [

            {

                "height": 4160,

                "html_attributions": [

                    "<a href=\"https://maps.google.com/maps/contrib/114373861275704723265\">יערה בקר</a>"

                ],

                "photo_reference": "ATtYBwJPmHyODpVekvQNiAEaYkVgcblqXstWW8gCRhDV93KNY4BJ8eu2SOnXj0ZLNFoesEA47kadkIIEFNNtlL_d-8cli_aTc20Qi02yFHTBswWhyLROOh7AkTSWzwCaOqaFjDpYRHiXaouQAthLc7_iyClV0bBIXn_ikbsWzLrlr3Ryhbib",

                "width": 3120

            }

        ],

        "place_id": "ChIJ8eHKNNUIHRUR6Ce4t9iy8YY",

        "plus_code": {

            "compound_code": "FXFC+WH Pardes Hanna-Karkur, Israel",

            "global_code": "8G4PFXFC+WH"

        },

        "rating": 4.8,

        "reference": "ChIJ8eHKNNUIHRUR6Ce4t9iy8YY",

        "scope": "GOOGLE",

        "types": [

            "veterinary_care",

            "point_of_interest",

            "establishment"

        ],

        "user_ratings_total": 149,

        "vicinity": "HaOranim Street 18, Pardes Hanna-Karkur"

    },

    {

        "business_status": "OPERATIONAL",

        "geometry": {

            "location": {

                "lat": 32.471729,

                "lng": 34.973782

            },

            "viewport": {

                "northeast": {

                    "lat": 32.4730747802915,

                    "lng": 34.97513418029149

                },

                "southwest": {

                    "lat": 32.4703768197085,

                    "lng": 34.9724362197085

                }

            }

        },

        "icon": "https://maps.gstatic.com/mapfiles/place_api/icons/v1/png_71/generic_business-71.png",

        "name": "ד\"ר תמר וטרינרית",

        "opening_hours": {

            "open_now": true

        },

        "photos": [

            {

                "height": 2500,

                "html_attributions": [

                    "<a href=\"https://maps.google.com/maps/contrib/113764155770280100997\">ד&quot;ר תמר וטרינרית</a>"

                ],

                "photo_reference": "ATtYBwJX6eKYmPkp9scFnsITaCoACk2WrESCc_jwD97FRtng6pnBsNEO9PWe7E9izkbCVBy46X_GIrORU9_FhgoGNdhQSqGItGOJbZAndiW6ig8ezHBetK52u9n8VJ0BUUByqLiuG4bbolu1-cu4co6oRfWQdVAfB7ZGpLoAvj9tWc0WRSjS",

                "width": 3750

            }

        ],

        "place_id": "ChIJucOIFTwOHRURXGwQdE1jWRU",

        "plus_code": {

            "compound_code": "FXCF+MG Pardes Hanna-Karkur, Israel",

            "global_code": "8G4PFXCF+MG"

        },

        "rating": 4.8,

        "reference": "ChIJucOIFTwOHRURXGwQdE1jWRU",

        "scope": "GOOGLE",

        "types": [

            "veterinary_care",

            "health",

            "point_of_interest",

            "establishment"

        ],

        "user_ratings_total": 16,

        "vicinity": "העצמאות 8 פרדס חנה כרכור"

    },

    {

        "business_status": "OPERATIONAL",

        "geometry": {

            "location": {

                "lat": 32.4772497,

                "lng": 34.9760424

            },

            "viewport": {

                "northeast": {

                    "lat": 32.47863428029149,

                    "lng": 34.9773649802915

                },

                "southwest": {

                    "lat": 32.4759363197085,

                    "lng": 34.9746670197085

                }

            }

        },

        "icon": "https://maps.gstatic.com/mapfiles/place_api/icons/v1/png_71/generic_business-71.png",

        "name": "Pluto veterinary clinic for pets",

        "opening_hours": {

            "open_now": true

        },

        "photos": [

            {

                "height": 801,

                "html_attributions": [

                    "<a href=\"https://maps.google.com/maps/contrib/111298533410600343021\">פלוטו מרפאה וטרינרית לחיות מחמד</a>"

                ],

                "photo_reference": "ATtYBwKsnx6YvMOjNzMZs0CdCkMkc1dGW4DWscoHBywWc6S0X4LjMuZu4lFMe-N4iQ1YHztn5tDbVmQfoL-RGGkPcn7MayICUjYr6PvIEjs2lKJwOJroTPvi2meVYjm4TSPMUzIeVGAn5lniSgSNNfEMdHFbJcPKyzfaN9bJ0eqy_jpHYE8r",

                "width": 1108

            }

        ],

        "place_id": "ChIJ_-GIz1UOHRURtquBqSmVbSs",

        "plus_code": {

            "compound_code": "FXGG+VC Pardes Hanna-Karkur, Israel",

            "global_code": "8G4PFXGG+VC"

        },

        "rating": 4.8,

        "reference": "ChIJ_-GIz1UOHRURtquBqSmVbSs",

        "scope": "GOOGLE",

        "types": [

            "veterinary_care",

            "point_of_interest",

            "establishment"

        ],

        "user_ratings_total": 57,

        "vicinity": "Derech HaSadeh 2, Pardes Hanna-Karkur"

    },

    {

        "business_status": "OPERATIONAL",

        "geometry": {

            "location": {

                "lat": 32.4679026,

                "lng": 34.95267579999999

            },

            "viewport": {

                "northeast": {

                    "lat": 32.46928543029149,

                    "lng": 34.95403453029149

                },

                "southwest": {

                    "lat": 32.46658746970849,

                    "lng": 34.9513365697085

                }

            }

        },

        "icon": "https://maps.gstatic.com/mapfiles/place_api/icons/v1/png_71/generic_business-71.png",

        "name": "הגורים של יעל",

        "place_id": "ChIJpR6D0AMPHRURBqKrZvv8Rng",

        "plus_code": {

            "compound_code": "FX93+53 Pardes Hanna-Karkur, Israel",

            "global_code": "8G4PFX93+53"

        },

        "reference": "ChIJpR6D0AMPHRURBqKrZvv8Rng",

        "scope": "GOOGLE",

        "types": [

            "veterinary_care",

            "point_of_interest",

            "establishment"

        ],

        "vicinity": "Pardes Hanna-Karkur"

    },

    {

        "business_status": "OPERATIONAL",

        "geometry": {

            "location": {

                "lat": 32.46755479999999,

                "lng": 34.9529721

            },

            "viewport": {

                "northeast": {

                    "lat": 32.4689189802915,

                    "lng": 34.9542401302915

                },

                "southwest": {

                    "lat": 32.4662210197085,

                    "lng": 34.9515421697085

                }

            }

        },

        "icon": "https://maps.gstatic.com/mapfiles/place_api/icons/v1/png_71/shopping-71.png",

        "name": "הגורים של אייל - מרכז לחיות מחמד",

        "opening_hours": {

            "open_now": true

        },

        "photos": [

            {

                "height": 3000,

                "html_attributions": [

                    "<a href=\"https://maps.google.com/maps/contrib/109690855352097816546\">עוז נתן</a>"

                ],

                "photo_reference": "ATtYBwJbFE9kTDmt3v3i06hrYn8i33RJhvXPLpxcfEZMAJM9gVAk46-25qoK_fYceMyNDbWGYQ5WcFOzP_j-0JZZLBEitoTf-g1lAFVUqbn12KAbV6LjOS2GAs8iupNrxyO96ERIn6U9ovHJ0DtnKMiSPhQ2eM0MWZPYbCA3glHtGtFVghIz",

                "width": 4000

            }

        ],

        "place_id": "ChIJa3uY0_APHRURw_-b9uTYelY",

        "plus_code": {

            "compound_code": "FX93+25 Pardes Hanna-Karkur, Israel",

            "global_code": "8G4PFX93+25"

        },

        "rating": 5,

        "reference": "ChIJa3uY0_APHRURw_-b9uTYelY",

        "scope": "GOOGLE",

        "types": [

            "veterinary_care",

            "point_of_interest",

            "store",

            "establishment"

        ],

        "user_ratings_total": 1,

        "vicinity": "Thiya Street 14, Pardes Hanna-Karkur"

    },

    {

        "business_status": "OPERATIONAL",

        "geometry": {

            "location": {

                "lat": 32.47625349999999,

                "lng": 34.9646279

            },

            "viewport": {

                "northeast": {

                    "lat": 32.4775961302915,

                    "lng": 34.9659865302915

                },

                "southwest": {

                    "lat": 32.4748981697085,

                    "lng": 34.9632885697085

                }

            }

        },

        "icon": "https://maps.gstatic.com/mapfiles/place_api/icons/v1/png_71/generic_business-71.png",

        "name": "יעל שכטר וטרינרית",

        "opening_hours": {

            "open_now": true

        },

        "photos": [

            {

                "height": 1200,

                "html_attributions": [

                    "<a href=\"https://maps.google.com/maps/contrib/109597738885773995125\">מרפאה וטרינרית יעל שכטר</a>"

                ],

                "photo_reference": "ATtYBwLM1hDUPUwJZKg4oF9kWJyqLQK5aGCP5P_wW9t49t7pzWZ7JCbA0GAFuJVgKVrOglkkmD5_wwZI4b3O1A8-dJGO8_j0Ejjafd1RwCnJfMNbBP7-5Yqc9pEKAFMSYB_Mvj6IoA81XLMQ_c5cxdFw50z1yyh9sDdL7uk10ZglDerrJsk_",

                "width": 1600

            }

        ],

        "place_id": "ChIJyVa6XkEOHRUR0gUvfghTbBk",

        "plus_code": {

            "compound_code": "FXG7+GV Pardes Hanna-Karkur, Israel",

            "global_code": "8G4PFXG7+GV"

        },

        "rating": 4.9,

        "reference": "ChIJyVa6XkEOHRUR0gUvfghTbBk",

        "scope": "GOOGLE",

        "types": [

            "veterinary_care",

            "point_of_interest",

            "establishment"

        ],

        "user_ratings_total": 54,

        "vicinity": "יש להגיע בתאום מראש, Simtat HaEla 11, Pardes Hanna-Karkur"

    },

    {

        "business_status": "OPERATIONAL",

        "geometry": {

            "location": {

                "lat": 32.480772,

                "lng": 34.968654

            },

            "viewport": {

                "northeast": {

                    "lat": 32.4821132802915,

                    "lng": 34.96998563029149

                },

                "southwest": {

                    "lat": 32.4794153197085,

                    "lng": 34.9672876697085

                }

            }

        },

        "icon": "https://maps.gstatic.com/mapfiles/place_api/icons/v1/png_71/generic_business-71.png",

        "name": "מרפאה וטרינרית",

        "opening_hours": {

            "open_now": true

        },

        "place_id": "ChIJp8MCye8PHRUR6G0JbkHxlzo",

        "plus_code": {

            "compound_code": "FXJ9+8F Pardes Hanna-Karkur, Israel",

            "global_code": "8G4PFXJ9+8F"

        },

        "rating": 2,

        "reference": "ChIJp8MCye8PHRUR6G0JbkHxlzo",

        "scope": "GOOGLE",

        "types": [

            "veterinary_care",

            "point_of_interest",

            "establishment"

        ],

        "user_ratings_total": 3,

        "vicinity": "Eshel Street, Pardes Hanna-Karkur"

    },

    {

        "business_status": "OPERATIONAL",

        "geometry": {

            "location": {

                "lat": 32.470741,

                "lng": 34.972445

            },

            "viewport": {

                "northeast": {

                    "lat": 32.4720978302915,

                    "lng": 34.9737857302915

                },

                "southwest": {

                    "lat": 32.4693998697085,

                    "lng": 34.9710877697085

                }

            }

        },

        "icon": "https://maps.gstatic.com/mapfiles/place_api/icons/v1/png_71/generic_business-71.png",

        "name": "אלאמה מרפאה וטרינרית",

        "opening_hours": {

            "open_now": true

        },

        "photos": [

            {

                "height": 4032,

                "html_attributions": [

                    "<a href=\"https://maps.google.com/maps/contrib/111751346789959475772\">Tamar Savtchenko</a>"

                ],

                "photo_reference": "ATtYBwK80DXoBgB_IZi5OAyACWWQ381heU_gQqtTT8ZUyBwHz1saJbJCsuu8h51OIDRZc0xq72Un9r5MbwKXiHN2KcDBxtWvyHycCnuTMsv9WKJKwTVpBv9m1kwox7FsoJU0Qm7K8KbSYe5Ci3R0hgO0FsFk_fScGo2pmxk6hTRaXhtATWXT",

                "width": 3024

            }

        ],

        "place_id": "ChIJ20Pqg2oOHRURY_OANoUZNR4",

        "plus_code": {

            "compound_code": "FXCC+7X Pardes Hanna-Karkur, Israel",

            "global_code": "8G4PFXCC+7X"

        },

        "rating": 5,

        "reference": "ChIJ20Pqg2oOHRURY_OANoUZNR4",

        "scope": "GOOGLE",

        "types": [

            "veterinary_care",

            "health",

            "point_of_interest",

            "establishment"

        ],

        "user_ratings_total": 10,

        "vicinity": "Atsma'ut Street 8, Pardes Hanna-Karkur"

    }

],

"status": "OK"

}

1 Like

Okay, I’m able to use that but I had to include the starting and ending brackets { }. I’ll take a look when I get a chance.

I tried it again with the full JSON response and I get a list viewer with lat values:

Here’s the demo project: Thunkable

Make sure you are checking the green error block’s value. If it’s crashing, you may be trying to reference a property that doesn’t exist in the JSON response, or trying to parse a JSON response that doesn’t exist (for example if “status” ≠ 200 or if you’re getting an error value).

Post a screenshot of your JSON call blocks – make sure to hide/remove the API key.

2 Likes