这是我的 json 回复:
{
"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"
}
我想要的是,"text" : "3,586 km"
在解析后添加到列表中。我试过的是:
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"));
我得到的错误是:Object["elements"] not found
请帮忙!