嘿家伙我有一个JSON文件,如下所示:
{"posts":[{"Latitude":"53.38246685","lontitude":"-6.41501535"},
{"Latitude":"53.4062787","lontitude":"-6.3767205"}]}
Run Code Online (Sandbox Code Playgroud)
我可以通过以下方式获得第一组纬度和纬度坐标:
JSONObject o = new JSONObject(s);
JSONArray a = o.getJSONArray("posts");
o = a.getJSONObject(0);
lat = (int) (o.getDouble("Latitude")* 1E6);
lng = (int) (o.getDouble("lontitude")* 1E6);
Run Code Online (Sandbox Code Playgroud)
有没有人知道如何获得所有的纬度和纬度值?
任何帮助将非常感激.
ArrayList为结果创建s:
JSONObject o = new JSONObject(s);
JSONArray a = o.getJSONArray("posts");
int arrSize = a.length();
List<Integer> lat = new ArrayList<Integer>(arrSize);
List<Integer> lon = new ArrayList<Integer>(arrSize);
for (int i = 0; i < arrSize; ++i) {
o = a.getJSONObject(i);
lat.add((int) (o.getDouble("Latitude")* 1E6));
lon.add((int) (o.getDouble("lontitude")* 1E6));
}
Run Code Online (Sandbox Code Playgroud)
这将覆盖任何数组大小,即使有两个以上的值.