{ "name": "John", "age": 30, "address": { "street": "123 Main St", "city": "Anytown", "state": "CA", "zip": "12345" } }
JSONObject jsonObject = new JSONObject(jsonString); JSONObject address = jsonObject.getJSONObject("address");
[ { "name": "John", "age": 30 }, { "name": "Jane", "age": 25 } ]
JSONArray jsonArray = new JSONArray(jsonString); JSONObject firstObject = jsonArray.getJSONObject(0);In both examples, we are using the getJSONObject method provided by the org.json library to retrieve a nested JSONObject.