JSONObject,JSONArray

JSON和JSONObject,JSONArray的关系,类似于Map和HashMap

JSONObject:{"name":"张三","sex":"男"}

JSONArray:[{"name":"张三","sex":"男"},{"name":"李四","sex":"男"}]

com.alibaba.fastjson.JSONObject obj = com.alibaba.fastjson.JSON.parseObject(getPrice(cityName));

com.alibaba.fastjson.JSONArray array2 = com.alibaba.fastjson.JSON.parseArray(obj.getString("PriceItems"));
int i = 0;
Map<String, Object> time = new HashMap<String, Object>();
for (Object a : array2) {
com.alibaba.fastjson.JSONObject o = (com.alibaba.fastjson.JSONObject) a;
time.put("Tstart" + i, o.get("Tstart"));
time.put("Tend" + i, o.get("Tend"));
time.put("Price" + i, o.get("Price"));
i++;
}

你可能感兴趣的:(JSONObject,JSONArray)