【发布时间】:2012-04-19 02:15:01
【问题描述】:
我需要能够从我已有的 JSONArray 中创建一个新的 JSONArray,在数组中我有很多称为 id 的字段,每行还有一个,我如何获得它们的列表?
例如。我把这个拿回来了
[{"id":111,"users":"blob"},
{"id":111,"users":"blob"},
{"id":111,"users":"blob"},
{"id":111,"users":"blob"},
{"id":111,"users":"blob"},
{"id":111,"users":"blob"}]
如何获得仅包含 ID 的列表?
- 编辑
决定在此之后直接使用 for 循环,但谢谢 :D
HttpResponse response = httpclient.execute(httpget); //execute the HttpPost request
JSONArray jsa = projectResponse(response); //get the json response
for(int i = 0; i < jsa.length(); i++){
JSONObject jso = jsa.getJSONObject(i);
publishProgress(jso.getString("id"), jso.getString("name"));
}
【问题讨论】:
-
用一个很好的老式
for循环构建一个新的JSONArray有什么问题? -
看到这篇文章。这将对您有所帮助。 stackoverflow.com/questions/2487841/…