6
使用Java访问JSONArray中项目的成员
我刚刚开始在Java中使用json。我不确定如何访问JSONArray中的字符串值。例如,我的json看起来像这样: { "locations": { "record": [ { "id": 8817, "loc": "NEW YORK CITY" }, { "id": 2873, "loc": "UNITED STATES" }, { "id": 1501 "loc": "NEW YORK STATE" } ] } } 我的代码: JSONObject req = new JSONObject(join(loadStrings(data.json),"")); JSONObject locs = req.getJSONObject("locations"); JSONArray recs = locs.getJSONArray("record"); 我现在可以访问“ record” JSONArray,但是不确定如何在for循环中获取“ id”和“ …