Reputation: 48592
I am developing an android application where I require to parse the JSON. I tried to parse but getting an exception.
JSONObject pontoReferencia = {"html_attributions":[],"status":"OK","result":{"utc_offset":330,"id":"9e66cc8fb57ff106b8d2f0b2bfc3a0098343b29b","icon":"http:\/\/maps.gstatic.com\/mapfiles\/place_api\/icons\/generic_business-71.png","vicinity":"Ashok Nagar, Jaipur","address_components":[{"types":["sublocality","political"],"short_name":"Ashok Nagar","long_name":"Ashok Nagar"},{"types":["locality","political"],"short_name":"Jaipur","long_name":"Jaipur"},{"types":["administrative_area_level_2","political"],"short_name":"Jaipur","long_name":"Jaipur"},{"types":["administrative_area_level_1","political"],"short_name":"Rajasthan","long_name":"Rajasthan"},{"types":["country","political"],"short_name":"IN","long_name":"IN"}],"name":"Axis Mall","formatted_address":"Ashok Nagar, Jaipur, Rajasthan, India","types":["shopping_mall","establishment"],"url":"https:\/\/plus.google.com\/102521013990997599439\/about?hl=en-US","reference":"CpQBggAAABI29kI2gyoevkgdjJzq0laeUzYt9SHoms1EM19Jgio6PS6inqWz8BICZRH728ez1evezArY72tB30e8BdF_PpYAgB5RzkamKzg30SR7zQusZm1KOWMvWNJRfIhPOQmh35nv_P4dNLzDoh1sTct3Ue20rw8driI4b93tuDLqBw7Fj22WG9arHKirmeUvbGfrkRIQQxj-Pqop8NJUwpwgxGBHKBoUrneQW_mt9s7SBLmNeTssG1HS8nw","geometry":{"location":{"lng":75.807495,"lat":26.910624}}}}
I am trying to fetch the URL like below but I am getting Exception.
String url = pontoReferencia.getString("url");
Exception : org.json.JSONException: No value for url.
Upvotes: 0
Views: 445
Reputation: 49572
The field url
is inside the json object result
. So you should try:
JSONObject result = pontoReferencia.getJSONObject("result");
String url = result.getString("url);
Upvotes: 3