Back to Top

Iterate through JSONObject in java (android)

Updated 16 July 2021

Assuming your JSON is in a string form, you can iterate over the attribute-value pairs as follows:

Below String jsonstring is the string of json.

String jsonstring = "{ "child": { "something": "value", "something2": "value" } }";
JSONObject resobj = new JSONObject(jsonstring);
Iterator<?> keys = resobj.keys();
while(keys.hasNext() ) {
    String key = (String);
    if ( resobj.get(key) instanceof JSONObject ) {
        JSONObject xx = new JSONObject(resobj.get(key).toString());

Searching for an experienced
Magento Company ?
Find out More
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*

Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home