大家好,我正在阅读一个包含 JAVA (Android) JSON 对象的页面
以下是该页面包含的内容:
{
"destination_addresses" : [ "Safi, Maroc" ],
"origin_addresses" : [ "Avenue Hassan II, Safi, Maroc" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "1,0 km",
"value" : 966
},
"duration" : {
"text" : "2 minutes",
"value" : 129
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}
我知道如何从页面中读取内容
JSONObject jArray = new JSONObject(result);
String elements = jArray.getString("rows");
元素字符串包含:
[{"elements" : [{"distance" : {"text" : "1,0 km","value" : 966},"duration" : {"text" : "2 minutes","value" : 129},"status" : "OK"}]}]
但我正在尝试获取距离值,即“966”
谢谢大家
最佳答案
因此您正在尝试访问数组中的条目。请参阅教程或示例。这是基本的东西: http://www.mkyong.com/java/json-simple-example-read-and-write-json/
您需要实际使用JSONArray (它是 JSONObject 的子类)
关于java - 使用Json访问特定属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21070770/