Good Day I have question about JSON parsing . How to get the value of distance with this json format
{
"destination_addresses" : [
"Davao City-Juction Digos Section Road, Talomo, Davao City, Davao del Sur, Philippines"
],
"origin_addresses" : [
"Roxas Ave, Poblacion District, Davao City, Davao del Sur, Philippines"
],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "10.8 km",
"value" : 10782
},
"duration" : {
"text" : "55 mins",
"value" : 3309
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}
These are my code:
JSONObject jObj = new JSONObject(result);
JSONObject a = jObj.getJSONObject("rows");
JSONObject b = a.getJSONObject("elements");
JSONObject c= b.getJSONObject("distance");
String est = c.getString("text");
String vals = c.getString("value");
These are the error :
aorouteguide.example.com.davaorouteguideapp E/MYAPP: unexpected JSON exception
org.json.JSONException: Value [{"elements":[{"distance":{"text":"31.4 km","value":31351},"duration":{"text":"1 hour 26 mins","value":5136},"status":"OK"}]}] at rows of type org.json.JSONArray cannot be converted to JSONObject