我正在應用程序中,我需要顯示所有的ATM。我從Google API獲取數據,但我無法獲取所有數據。我想獲取latitude
和longitude
,但是當我獲取數據時,我只能獲得一個值。如何在JSONARRAY中從JSONOBJECT獲取值?
String url = "https://maps.googleapis.com/maps/api/place/radarsearch/json?location=23.308003,81.3275914&radius=5000&type=atm&key=AIzaSyCYZoSkxHC_Exym4YBWvXZXwMyJA7dzEB4";
try {
JSONObject jObject = new JSONObject(request(url));
String jj = jObject.getString("status");
JSONArray data = jObject.getJSONArray("results");
location = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map;
for(int i = 0; i < data.length(); i++){
JSONObject c = data.getJSONObject(i);
map = new HashMap<String, String>();
JSONObject geometry = c.getJSONObject("geometry");
JSONObject locate = geometry.getJSONObject("location");
String lat = locate.getString("lat");
String lng = locate.getString("lng");
Log.e("Data", lat+"--"+lng);
//map.put("LocationID", c.getString("id"));
//map.put("placeId",c.getString("place_id"));
//location.add(map);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
後你還沒有把你從Json的在位置得到緯度經度的值( HashMap) –
@ user3810679我建議您閱讀有關Retrofit和GSON/Jackson的信息 – DeKaNszn
Possibl e [發送和解析JSON對象]的副本(https://stackoverflow.com/questions/2818697/sending-and-parsing-json-objects) –