Created
August 5, 2019 22:46
-
-
Save parzibyte/a9ca424c5421362c04445681a4dda54d to your computer and use it in GitHub Desktop.
Iterate JsonArray in Java - https://parzibyte.me/blog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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