小编use*_*679的帖子

如何从JSONARRAY中的JSONOBJECT获取值?

我正在申请,我需要显示所有的ATM.我从谷歌api获取数据,但我无法获取所有数据.我想要获取latitude,longitude但是当我获取数据时,我只获得一个值.

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 …
Run Code Online (Sandbox Code Playgroud)

android json android-json

2
推荐指数
1
解决办法
674
查看次数

标签 统计

android ×1

android-json ×1

json ×1