0

I' using Google API to return a place and then I access it using JsonValue. Everything works when I want to access results, when I go 'deeper" I get timeout exceptions. How to access other objects and iterate through a JSON object?

The response:

{
   "html_attributions" : [],
   "results" : [
      {
         "geometry" : {
            "location" : {
               "lat" : -33.867551,
               "lng" : 151.200817
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
         "id" : "b0277cade7696e575824681aba949d68814f9efe",
         "name" : "Sydney New Year's Eve Cruises",
         "opening_hours" : {
            "open_now" : false,
            "weekday_text" : []
         },
         "photos" : [
            {
               "height" : 813,
               "html_attributions" : [
                  "\u003ca href=\"https://maps.google.com/maps/contrib/107666140764925298472/photos\"\u003eSydney New Year's Eve Cruises\u003c/a\u003e"
               ],
               "photo_reference" : "CoQBcwAAAF5NycTw0r7cw8CHxZCKNvFGUSFndKXuPT4j5lXZXI_T-1SkRfdGwhayhQdRD0-4omka8cFZc02E8grQ7t8LduyznGgIBCocN24QLznNY2q9x3FmW-d-Ry74CNo3WX0YQKXg2JqIbXRH86X-X_TXGNrc75_fQwd-x8CE2-MeaVn3EhD1hfBnjPtXGv9QS234kiOIGhStf_EjMEL53bwDKocQ5cw3iYhCUA",
               "width" : 1300
            }
         ],
         "place_id" : "ChIJ__8_hziuEmsR27ucFXECfOg",
         "reference" : "CoQBcQAAAEW7axO9F7XCp3AMXS6VjAOYY4g-pzVSmvZmC3kARg7wHywP_jI4tbNSD01q0hzdqxfe9fHxruuNeaaM-5VWKiNumQuFBKYAitfKlUGB8BxQlnJ3jef_7hVgquryh4Vm2Qo9EOl9-BLlpdHt0tdMDQhZHK3XKVMf024gWYP3F1sxEhBVaaVAe3r51tlCIsn_-z48GhQiawR_3Sh9KQOJ2wNqjoh42FazBA",
         "scope" : "GOOGLE",
         "types" : [
            "travel_agency",
            "restaurant",
            "food",
            "point_of_interest",
            "establishment"
         ],
         "vicinity" : "32 The Promenade, King Street Wharf 5, Sydney Nsw 2000, Sydney"
      }
   ],
   "status" : "OK"
}

C#:

JsonValue json = await FetchDataAsync (url);
JsonValue resultsJson = json["results"];

A am able to see the response in resultsJson, but when I try to access geometry straight after resultsJson using:

JsonValue geometryJson = resultsJson["geometry"];

I get timeout exceptions. What am I doing wrong?

1 Answer 1

2

Because results is an array, you should try something like this:

json["results"][0]["geometry"]
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @WPMed - I'm pretty new to C#, but I can see how to access nested objects

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.