JSONArray jsonArray = new JSONArray("[1, 2, 3, 4, 5]"); int elementAtIndexTwo = jsonArray.getInt(2); // returns 3
JSONArray jsonArray = new JSONArray("[{\"name\": \"John\", \"age\": 30}, {\"name\": \"Jane\", \"age\": 25}]"); JSONObject secondObject = jsonArray.getJSONObject(1); String name = secondObject.getString("name"); // returns "Jane"In the above example, we create a JSONArray with two JSONObjects. We use the `get` method to retrieve the JSONObject at index `1`. We then get the value of the `name` property in the second JSONObject, which is `Jane`. Package library: org.json