在我需要解析地点的类型之前一切顺利,文件的组织方式如下:
"geometry" : {
"location" : {
"lat" : 45.7849210,
"lng" : 11.8724490
},
"viewport" : {
"northeast" : {
"lat" : 45.81619110,
"lng" : 11.89575470
},
"southwest" : {
"lat" : 45.75432980,
"lng" : 11.84532520
}
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
"id" : "a454072e2ba71d4e2331e39099261f086cd11d1e",
"name" : "Fonte",
"reference" : "CnRtAAAAUaGSsbXRv05lApqXueEKjOAjtkpEDz07ioe3vPS9HqpOIJSTTQWYObc6o6GfEq-pzVUtKT03oRWNx6ld-rUfdat47e8W3NbSsLY1NldO9iQEUjQOM9kIIOix8xLAvqh5YHUNTAela4Mo8HGSJPPBhhIQ9j4Uy_WrQtFO7qxirA0UHRoUsmY0ngstG5BBiHQNLkLgxTpsDEY",
"types" : [ "locality", "political" ],
"vicinity" : "Fonte"
},
由于可能会注意到 types 是一个字符串数组,因此我尝试了这种方法:
JSONArray results = o.getJSONArray("results");
JSONObject tempObject = results.getJSONObject(0);
JSONArray typee = tempObject.getJSONArray("types");
String a = typee.getJSONObject(0).toString();
但它不起作用。任何帮助将不胜感激。整个 JSON 可以在这里看到:https ://maps.googleapis.com/maps/api/place/search/json?location=45.7909,11.8700&radius=500&key= AIzaSyC9Ob9_u-2mxCHeItDHytDLmZP-P1QCejw&sensor=true。