javascript - Extracting a property several levels deep from JSON -


code:

ienumerator radar() {     radarurl = "https://maps.googleapis.com/maps/api/geocode/json?latlng="+ "43.761223" + "," + "11.280470" + "&key=" + apikey;     www googleresp = new www(radarurl);     yield return googleresp;     googlerespstr =  googleresp.text;     jsonnode jsonreturn = json.parse(googleresp.text);     string results = jsonreturn["results"]["formatted_address"].value;     debug.log(jsonreturn["results"]["formatted_address"].value);     textdebug.text = jsonreturn;     debug.log(jsonreturn);  } 

output json:

{   "results" : [       {          "address_components" : [             {                "long_name" : "45-47",                "short_name" : "45-47",                "types" : [ "street_number" ]             },             {                "long_name" : "via bartolomeo scala",                "short_name" : "via bartolomeo scala",                "types" : [ "route" ]             },             {                "long_name" : "firenze",                "short_name" : "firenze",                "types" : [ "locality", "political" ]             },             {                "long_name" : "firenze",                "short_name" : "firenze",                "types" : [ "administrative_area_level_3", "political" ]             },             {                "long_name" : "città metropolitana di firenze",                "short_name" : "fi",                "types" : [ "administrative_area_level_2", "political" ]             },             {                "long_name" : "toscana",                "short_name" : "toscana",                "types" : [ "administrative_area_level_1", "political" ]             },             {                "long_name" : "italia",                "short_name" : "it",                "types" : [ "country", "political" ]             },             {                "long_name" : "50126",                "short_name" : "50126",                "types" : [ "postal_code" ]             }          ],          "formatted_address" : "via bartolomeo scala, 45-47, 50126 firenze, italia",          "geometry" : {             "bounds" : {                "northeast" : {                   "lat" : 43.7613726,                   "lng" : 11.2806527                },                "southwest" : {                   "lat" : 43.76119389999999,                   "lng" : 11.2803103                }             },             "location" : {                "lat" : 43.76124780000001,                "lng" : 11.2804451             },             "location_type" : "range_interpolated",             "viewport" : {                "northeast" : {                   "lat" : 43.76263223029149,                   "lng" : 11.2818304802915                },                "southwest" : {                   "lat" : 43.7599342697085,                   "lng" : 11.2791325197085                }             }          },          "place_id" : "ejjwawegqmfydg9sb21lbybty2fsyswgndutndcsiduwmti2iezpcmvuemusiel0ywxpyq",          "types" : [ "street_address" ]       },       {          "address_components" : [             {                "long_name" : "firenze",                "short_name" : "firenze",                "types" : [ "locality", "political" ]             },             {                "long_name" : "firenze",                "short_name" : "firenze",                "types" : [ "administrative_area_level_3", "political" ]             },             {                "long_name" : "città metropolitana di firenze",                "short_name" : "fi",                "types" : [ "administrative_area_level_2", "political" ]             },             {                "long_name" : "toscana",                "short_name" : "toscana",                "types" : [ "administrative_area_level_1", "political" ]             },             {                "long_name" : "italia",                "short_name" : "it",                "types" : [ "country", "political" ]             }          ],          "formatted_address" : "firenze, italia",          "geometry" : {             "bounds" : {                "northeast" : {                   "lat" : 43.8329368,                   "lng" : 11.3278993                },                "southwest" : {                   "lat" : 43.7269795,                   "lng" : 11.1540365                }             },             "location" : {                "lat" : 43.7695604,                "lng" : 11.2558136             },             "location_type" : "approximate",             "viewport" : {                "northeast" : {                   "lat" : 43.8329368,                   "lng" : 11.3278993                },                "southwest" : {                   "lat" : 43.7269795,                   "lng" : 11.1540365                }             }          },          "place_id" : "chijrdbsgkzwkhmrayrh7xd51zm",          "types" : [ "locality", "political" ]       },       {          "address_components" : [             {                "long_name" : "50126",                "short_name" : "50126",                "types" : [ "postal_code" ]             },             {                "long_name" : "firenze",                "short_name" : "firenze",                "types" : [ "administrative_area_level_3", "political" ]             },             {                "long_name" : "città metropolitana di firenze",                "short_name" : "fi",                "types" : [ "administrative_area_level_2", "political" ]             },             {                "long_name" : "toscana",                "short_name" : "toscana",                "types" : [ "administrative_area_level_1", "political" ]             },             {                "long_name" : "italia",                "short_name" : "it",                "types" : [ "country", "political" ]             }          ],          "formatted_address" : "50126 firenze fi, italia",          "geometry" : {             "bounds" : {                "northeast" : {                   "lat" : 43.7661839,                   "lng" : 11.321206                },                "southwest" : {                   "lat" : 43.7383011,                   "lng" : 11.267919                }             },             "location" : {                "lat" : 43.7592388,                "lng" : 11.2920619             },             "location_type" : "approximate",             "viewport" : {                "northeast" : {                   "lat" : 43.7661839,                   "lng" : 11.321206                },                "southwest" : {                   "lat" : 43.7383011,                   "lng" : 11.267919                }             }          },          "place_id" : "chijrs-jdz1tkhmrio59qpqscbw",          "types" : [ "postal_code" ]       },       {          "address_components" : [             {                "long_name" : "firenze",                "short_name" : "firenze",                "types" : [ "administrative_area_level_3", "political" ]             },             {                "long_name" : "città metropolitana di firenze",                "short_name" : "fi",                "types" : [ "administrative_area_level_2", "political" ]             },             {                "long_name" : "toscana",                "short_name" : "toscana",                "types" : [ "administrative_area_level_1", "political" ]             },             {                "long_name" : "italia",                "short_name" : "it",                "types" : [ "country", "political" ]             }          ],          "formatted_address" : "firenze fi, italia",          "geometry" : {             "bounds" : {                "northeast" : {                   "lat" : 43.8352047,                   "lng" : 11.3391437                },                "southwest" : {                   "lat" : 43.7258401,                   "lng" : 11.1506007                }             },             "location" : {                "lat" : 43.7890761,                "lng" : 11.2297105             },             "location_type" : "approximate",             "viewport" : {                "northeast" : {                   "lat" : 43.8352047,                   "lng" : 11.3391437                },                "southwest" : {                   "lat" : 43.7258401,                   "lng" : 11.1506007                }             }          },          "place_id" : "chij30yk06bwkhmr2zdgiwilrbo",          "types" : [ "administrative_area_level_3", "political" ]       },       {          "address_components" : [             {                "long_name" : "città metropolitana di firenze",                "short_name" : "fi",                "types" : [ "administrative_area_level_2", "political" ]             },             {                "long_name" : "toscana",                "short_name" : "toscana",                "types" : [ "administrative_area_level_1", "political" ]             },             {                "long_name" : "italia",                "short_name" : "it",                "types" : [ "country", "political" ]             }          ],          "formatted_address" : "città metropolitana di firenze, italia",          "geometry" : {             "bounds" : {                "northeast" : {                   "lat" : 44.239233,                   "lng" : 11.7529629                },                "southwest" : {                   "lat" : 43.4522844,                   "lng" : 10.7111173                }             },             "location" : {                "lat" : 43.7679178,                "lng" : 11.2523792             },             "location_type" : "approximate",             "viewport" : {                "northeast" : {                   "lat" : 44.239233,                   "lng" : 11.7529629                },                "southwest" : {                   "lat" : 43.4522844,                   "lng" : 10.7111173                }             }          },          "place_id" : "chijy3a9ekd4khmryidk45ascam",          "types" : [ "administrative_area_level_2", "political" ]       },       {          "address_components" : [             {                "long_name" : "toscana",                "short_name" : "toscana",                "types" : [ "administrative_area_level_1", "political" ]             },             {                "long_name" : "italia",                "short_name" : "it",                "types" : [ "country", "political" ]             }          ],          "formatted_address" : "toscana, italia",          "geometry" : {             "bounds" : {                "northeast" : {                   "lat" : 44.4726899,                   "lng" : 12.3713555                },                "southwest" : {                   "lat" : 42.2384378,                   "lng" : 9.6867213                }             },             "location" : {                "lat" : 43.7710513,                "lng" : 11.2486208             },             "location_type" : "approximate",             "viewport" : {                "northeast" : {                   "lat" : 44.4726899,                   "lng" : 12.3713555                },                "southwest" : {                   "lat" : 42.23844280000001,                   "lng" : 9.6867213                }             }          },          "place_id" : "chijezsaefmr1birq1kgw7rdxro",          "types" : [ "administrative_area_level_1", "political" ]       },       {          "address_components" : [             {                "long_name" : "italia",                "short_name" : "it",                "types" : [ "country", "political" ]             }          ],          "formatted_address" : "italia",          "geometry" : {             "bounds" : {                "northeast" : {                   "lat" : 47.092,                   "lng" : 18.5205015                },                "southwest" : {                   "lat" : 35.4929201,                   "lng" : 6.6267201                }             },             "location" : {                "lat" : 41.87194,                "lng" : 12.56738             },             "location_type" : "approximate",             "viewport" : {                "northeast" : {                   "lat" : 47.092,                   "lng" : 18.5205015                },                "southwest" : {                   "lat" : 35.4929201,                   "lng" : 6.6267201                }             }          },          "place_id" : "chija9knril-1birb15jjfz1loi",          "types" : [ "country", "political" ]       }    ],    "status" : "ok" } 

i have problem json. extract "formatted_address" (in case: "via bartolomeo scala, 45-47, 50126 firenze, italia").

i tried:

debug.log(jsonreturn["results"]["formatted_address"].value); 

but doesn't work. correct code?

enter image description herei noticed result array. need access first element of array:

jsonreturn["results"][0]["formatted_address"].value 

resource: http://wiki.unity3d.com/index.php/simplejson


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -