我的版本是Android 2.2 Google API 8,我从模拟器运行。我尝试访问此JSON对象中的长访问位置。我使用后我得到这个Android - 如何解析JSONObject和JSONArrays
InputStream instream = entity.getContent();
JSONObject myAwway = new JSONObject(convertStreamToString(instream));
谷歌文档说,它返回一个数组,但与周围的大括号它看起来像一个对象。
我需要访问位置字段中的纬度和经度,并存储为双打。
我已经搜索,但似乎只能找到简单文件的帮助。
{
"results" : [
{
"address_components" : [
{
"long_name" : "20059",
"short_name" : "20059",
"types" : [ "postal_code" ]
},
{
"long_name" : "Washington D.C.",
"short_name" : "Washington D.C.",
"types" : [ "locality", "political" ]
},
{
"long_name" : "District of Columbia",
"short_name" : "DC",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Washington D.C., DC 20059, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 38.924920,
"lng" : -77.0178720
},
"southwest" : {
"lat" : 38.9189910,
"lng" : -77.02261200000001
}
},
"location" : {
"lat" : 38.92177780,
"lng" : -77.01974260
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 38.92510312068017,
"lng" : -77.01709437931984
},
"southwest" : {
"lat" : 38.91880787931983,
"lng" : -77.02338962068018
}
}
},
"types" : [ "postal_code" ]
}
],
"status" : "OK"
}
JSONArray结果中只有一个元素。 – 2011-06-14 22:00:00
哎呀,好的电话。 – 2011-06-14 23:29:01