我是新來的android編程,我想知道如何從JSONarray獲得某個對象。我怎麼能從JSON數組中獲得JSONObject
我的JSON是這樣的:
{"results" : [
{
"address_components" : [
{
"long_name" : "Contern",
"short_name" : "Contern",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Luxembourg",
"short_name" : "Luxembourg",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Luxembourg",
"short_name" : "LU",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Contern, Luxembourg",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 49.621830,
"lng" : 6.302790
},
"southwest" : {
"lat" : 49.56759010,
"lng" : 6.195380
}
},
"location" : {
"lat" : 49.58515930,
"lng" : 6.2274880
},
,我想提取位置的緯度和經度。 我的代碼是:
arr = json.getJSONArray("results");
JSONObject location=arr.getJSONObject(4);
double lng = location.getDouble("lng");
double lat = location.getDouble("lat");
你現在得到什麼和期待什麼? – RvdK
請發佈您的整個json字符串。 –