Is it possible to iterate through JSONArray? [duplicate] Ask Question

Is it possible to iterate through JSONArray? [duplicate] Ask Question

Possible Duplicates:
JSON Array iteration in Android/Java
JSONArray with Java

Is it possible to iterate through JSONArray object using Iterator?

ベストアンサー1

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);
}

おすすめ記事