开发者

Is it possible to iterate through JSONArray? [duplicate]

开发者 https://www.devze.com 2023-02-06 05:36 出处:网络
This question already has answers here: Closed 12 years ago. Possible Duplicates: JSON Array iteration in Android/Java
This question already has answers here: Closed 12 years ago.

Possible Duplicates:

JSON Array iteration in Android/Java

JSONArray with Java

Is it possible to iterate through JSONArray object using 开发者_如何学JAVAIterator?


Not with an iterator.

For org.json.JSONArray, you can do:

for (int i = 0; i < arr.length(); i++) {
  arr.getJSONObject(i);
}

For javax.json.JsonArray, you can do:

for (int i = 0; i < arr.size(); i++) {
  arr.getJsonObject(i);
}


You can use the opt(int) method and use a classical for loop.

0

精彩评论

暂无评论...
验证码 换一张
取 消