【发布时间】:2015-06-11 12:55:39
【问题描述】:
我正在尝试将所有 JSONobject arrivals 添加到外部的 for 循环 JSONobject stops 中,但我总是在 stops 中得到一个 JSONObject。如何将所有arrivales JSONObject 放在 JSONObject stops 的 for 循环中?
我正在使用 json 库 org.json。
感谢您的帮助
JSONObject stops = new JSONObject();
for (Entry<String, List<String>> entry : map.entrySet()) {
String key = entry.getKey();
List<String> timeEntries = entry.getValue();
try {
stops.put("stops_name", key);
JSONObject arrivals = new JSONObject();
JSONArray arrivalMoFr = new JSONArray();
JSONArray timeArray = new JSONArray(timeEntries);
arrivalMoFr.put( timeArray);
arrivals.put("mon-fri", arrivalMoFr);
stops.put("arrival_time", arrivals);
System.out.println(stops.toString(3));
} catch (JSONException e) {
e.printStackTrace();
}
}
【问题讨论】: