Parsing json Inner Array -java
This is my json response :
{
"destination_addresses" : [ "Perkinston, MS, USA" ],
"origin_addresses" : [ "Sunnyvale, CA, USA" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "3,586 km",
"value" : 3585861
},
"duration" : {
"text" : "1 day 8 hours",
"value" : 115992
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}
What I want is, to add "text" : "3,586 km" in a list after parsing it.
What I Have tried is :
jsonObj = new JSONObject(response);
List<String> list = new ArrayList<String>();
JSONArray array = jsonObj.getJSONArray("rows");
System.out.println("size:"+array.length());
for(i = 0 ; i < array.length() ; i++){
JSONObject objects = new JSONObject(array.getJSONObject(i));
JSONArray element = objects.getJSONArray("elements");
JSONObject distance = new JSONObject(element.getJSONObject(i));
list.add(element.getJSONObject("").getString("text"));
This is the Error that I am getting: Object["elements"] not found
Any suggestion, how to parse it?
No comments:
Post a Comment