我无法从以下json获取纬度,经度(保持在json变量中)我从http请求获得:
{
"name": "rue de la paix, paris, france",
"Status": {
"code": 200,
"request": "geocode"
},
"Placemark": [ {
"id": "p1",
"address": "Rue de la Paix, 75002 Paris, France",
"AddressDetails": {
"Accuracy" : 6,
"Country" : {
"AdministrativeArea" : {
"AdministrativeAreaName" : "Ile-de-France",
"SubAdministrativeArea" : {
"Locality" : {
"LocalityName" : "Paris",
"PostalCode" : {
"PostalCodeNumber" : "75002"
},
"Thoroughfare" : {
"ThoroughfareName" : "Rue de la Paix"
}
},
"SubAdministrativeAreaName" : "Paris"
}
},
"CountryName" : "France",
"CountryNameCode" : "FR"
}
},
"ExtendedData": {
"LatLonBox": {
"north": 48.8724046,
"south": 48.8661093,
"east": 2.3343785,
"west": 2.3280833
}
},
"Point": {
"coordinates": [ 2.3312296, 48.8692714, 0 ]
}
} ]
}
我首先使用以下代码获取“Placemark”JSONArray:
JSONArray array = json.optJSONArray("Placemark");
没关系。 但我无法得到“点”对象......
JSONObject coordinates_json_obj = json.optJSONArray("Placemark").getJSONObject(4);
=> JSONArray[4] not found.
你有什么线索吗? 非常感谢, LUC
答案 0 :(得分:4)
Placemark数组中只有一个对象。 Point是该对象中的条目。
这样做,也许:
JSONObject coordinates_json_obj = json.optJSONArray("Placemark").get(0).getJSONObject("Point");