Quantcast
Channel: Loop through nested JSON array - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Loop through nested JSON array

$
0
0

I have a JSON response that looks like this:

{"1":{"id":"1","user_id":"1","children":[            {"id":"2","user_id":"2","children":[                    {"id":"3","user_id":"3","children":[                            {"id":"4","user_id":"2","children":[                                ]                            }                        ]                    },                    {"id":"5","user_id":"1","children":[                        ]                    }                ]            },            {"id":"6","user_id":"2","children":[                ]            }        ]    },"7":{"id":"7","user_id":"2",        ...    }}

As you can see, I have nested arrays (children). I need to loop through this JSON response, going through each nested array until it runs into an empty children array, and then takes a step back to continue to the rest of the items.

I made a model class for the response, so my current code looks like this:

for (Post post : postResponse.getData()) {    //}

Which obviously only iterates through the top-level items (id 1 and 7 in my case).

How can I do this?


Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>