【发布时间】:2018-01-25 09:15:50
【问题描述】:
我下载了以下格式的 JSON 文件:
{
"name": "enter_username",
"longitude": "22.601952",
"latitude": "40.674065",
"type": "Big_Pothole"
}
(这是实际的文件http://zachtsou.webpages.auth.gr/FetchLocationData.php)。
我将它们存储在不同的ArrayLists 中。
例如:
private void getDBLocations(JSONArray j){
dblocations = new ArrayList<LatLng>();
name = new ArrayList<>();
types = new ArrayList<String>();
full= new ArrayList<>();
// Traversing through all the items in the Json array
for(int i=0;i<j.length();i++){
try{
//Getting json object
JSONObject json = j.getJSONObject(i);
// Adding types to array list
names.add(json.getString(Config.TAG_NAME));
type.add(json.getString(Config.TAG_TYPE));
longitude.add(json.getDouble(Config.TAG_LONGITUDE));
latitude.add(json.getDouble(Config.TAG_LATITUDE));
}catch (JSONException e){
e.printStackTrace();
}
// Combining Longitude and Latitude on ArrayList<LatLon>
dblocations.add(new LatLng(latitude.get(i), longitude.get(i)));
}
}
我想创建一个常见的ArrayList,以便能够将其转移到新活动(例如谷歌地图活动)并使用 for 循环打印所有项目。
【问题讨论】: