{
"destination_addresses" : [ "Bombay, Maharashtra, Inde" ],
"origin_addresses" : [ "New Delhi, New Delhi 110001, Inde" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "1 457 km",
"value" : 1457222
},
"duration" : {
"text" : "22 heures 8 minutes",
"value" : 79663
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}
回答
请使用以下代码作为参考。
JSONObject jsonObject = new JSONObject("jsonResponse");
JSONArray jsonArr= jsonObj.getJSONArray("destination_addresses");
String[] arrDestinations=new String[jsonArr.lLength()];
for(int i=0;i<jsonArr.length();i++)
arrDestinations[i]=jsonArr.get(i);
jsonArr= jsonObj.getJSONArray("origin_addresses");
String[] arrOrigins=new String[jsonArr.lLength()];
for(int i=0;i<jsonArr.length();i++)
arrOrigins[i]=jsonArr.get(i);
JSONArray rows = jsonObj.getJSONArray("rows");
for(int i =0; i < rows.length(); i++)
{
JSONObject rowObj = rows.getJSONObject(i);
JSONArray rowElements = rowObj.getJSONArray("elements");
for(int element = 0; element < rowElements.length(); element++) {
// get the elements and parse
}
}
希望这会有所帮助。
谢谢你回复我已经追踪了json文档:) –
如果这对你有帮助,那么请upvote并接受答案:) –
检查您的Logcat
以查看JsonObject
中提取的值。
try {
JSONObject jsonObj = new JSONObject(JsonObject.toString());
JSONArray destination_addresses = jsonObj.getJSONArray("destination_addresses");
for (int i = 0; i < destination_addresses.length(); i++) {
Log.e("Values", "destination_addresses = " + destination_addresses.get(i));
}
JSONArray origin_addresses = jsonObj.getJSONArray("origin_addresses");
for (int i = 0; i < origin_addresses.length(); i++) {
Log.e("Values", "origin_addresses = " + origin_addresses.get(i));
}
JSONArray rows = jsonObj.getJSONArray("rows");
for (int i = 0; i < rows.length(); i++) {
JSONObject rowObject = rows.getJSONObject(i);
JSONArray rowElements = rowObject.getJSONArray("elements");
for (int j = 0; j < rowElements.length(); j++) {
JSONObject elementObject = rowElements.getJSONObject(j);
JSONObject distanceObject = elementObject.getJSONObject("distance");
String distanceText = distanceObject.getString("text");
String distanceValue = distanceObject.getString("value");
JSONObject durationObject = elementObject.getJSONObject("duration");
String durationText = distanceObject.getString("text");
String durationValue = distanceObject.getString("value");
Log.e("Values", "distanceText = " + distanceText + "\ndistanceValue = " + distanceValue + "\ndurationText = " + durationText + "\ndurationValue = " + durationValue);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
感谢您的回复我已追踪到JSON文档:) –
欢迎:) @HarshaVardhan –
第一件事我已经将它转换成json Hirarchy树,然后我明白解析:)此工具确实有助于http ://basic4ppc.com:51042/JSON/index.html的 –
我写了一个库,用于分析和Android中产生JSON: http://github.com/amirdew/JSON
- 1. 如何使用Volley解析JSON请求?
- 2. 如何使用Volley解析JSON结果?
- 3. 如何使用Volley解析JSON?
- 4. 如何使用volley解析json数据
- 5. 如何使用Volley库解析JSON数组?
- 6. 嵌套的JSON对象解析在android中使用volley
- 7. 解析json代码到android中的字符串使用volley
- 8. Android Volley JSON解析问题NULL检查
- 9. `错误:org.json.JSONException`为json解析使用volley
- 10. 使用Volley的Android Studio JSON解析:获取NullPointerException
- 11. 如何使用org-json库解析json?
- 12. 如何使用volley解析rss提要?
- 13. 如何使用Volley获取和解析JSON对象
- 14. 如何使用volley JSON android实现SearchView?
- 15. 如何解析使用android的json url?
- 16. 使用Gson库解析Android JSON
- 17. Volley org.json.JSONException当解析有效的JSON
- 18. JSON解析使用简单的JSON库
- 19. 使用API解析Android JSON
- 20. Android Json使用Gson解析
- 21. 如何解析JSON文件,而无需使用JSON库和JSON解析器
- 22. android如何解析json
- 23. 如何解析.netcore类库中的JSON
- 24. 如何使用JSON解析
- 25. 如何使用Json解析?
- 26. 如何解析Android中的json对象?
- 27. 如何解析Android中的JSON
- 28. 如何解析另一个JSONObject内的JSONObject,使用Android Volley进行HTTP连接
- 29. 从JSON使用Volley的Android ImageAdapter
- 30. JSON解析Android中
你写的代码只。没有任何关于你想做什么的解释,我怎能甚至试图帮助你? – phaberest
解析到ListView?看看这个:http://www.androidhive.info/2012/01/android-json-parsing-tutorial/ –