安卓解析服务端数据

1、解析服务端返回的Array

1.1、服务端返回的数据格式

[{
	"longitude": 113.954318,
	"latitude": 22.532004
}, {
	"longitude": 113.954318,
	"latitude": 22.532004
}]

1.2、安卓端的处理

import org.json.JSONArray;
import org.json.JSONException;     

            @Override
            public void onSuccess(Object responseObj) {
                try {
                    JSONArray jsonArray = new JSONArray(responseObj.toString());
                    LogUtils.d(jsonArray.toString());

                    List<LatLng> latLngs = new ArrayList<>();

                    if (jsonArray.length() > 0) {
                        for (int i = 0; i < jsonArray.length(); i++) {
                            double latitude = Double.parseDouble(
                                    jsonArray.getJSONObject(i).getString("latitude"));
                            double longitude = Double.parseDouble(
                                    jsonArray.getJSONObject(i).getString("longitude"));
                            LatLng latLng = new LatLng(latitude, longitude);
                            latLngs.add(latLng);
                        }
                    }
                    handleLatLngList(latLngs);


                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }
发布了650 篇原创文章 · 获赞 805 · 访问量 59万+

猜你喜欢

转载自blog.csdn.net/songzi1228/article/details/105072824