Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created August 5, 2019 22:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/a9ca424c5421362c04445681a4dda54d to your computer and use it in GitHub Desktop.
Save parzibyte/a9ca424c5421362c04445681a4dda54d to your computer and use it in GitHub Desktop.
Iterate JsonArray in Java - https://parzibyte.me/blog
// Nota: aquí jsonArray debería venir de una API externa u otro lugar
JSONArray jsonArray = new JSONArray();
for (int i = 0; i < jsonArray.length(); i++) {
try {
JSONObject jsonObject = jsonArray.getJSONObject(i);
if (jsonObject.has("clave")) {
String valor = jsonObject.getString("clave");
// Aquí hacer algo con el valor
}
} catch (JSONException e) {
e.printStackTrace();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment