java - Get value out JSON Object containing JSON arrays -


how can value of "distance" out of following json object java?

{   "destination_addresses" : [ "new york city, new york, verenigde staten" ],   "origin_addresses" : [ "washington d.c., district of columbia, verenigde staten" ],   "rows" : [     {        "elements" : [           {              "distance" : {                 "text" : "225 mijl",                 "value" : 361714              },              "duration" : {                 "text" : "3 uur 51 min.",                 "value" : 13877              },              "status" : "ok"           }        ]     }  ],  "status" : "ok" }       

i tried: json.getjsonarray("rows").getjsonobject(0).getjsonobject("distance").tostring();

but org.json.jsonexception: jsonobject["distance"] not found.

i think missing second array "elements", find array "row" object 0, in object 0 need find "elements" array take object 0 again, can "distance" object.

try this:

json.getjsonarray("rows").getjsonobject(0).getjsonarray("elements").getjsonobject(0).getjsonobject("distance").tostring(); 

again, think. hope helped you.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -