Let’s say I am dealing with JSON like this:
http://hndroidapi.appspot.com/nestedcomments/format/json/id/4620423?appid=hntoolbar&callback=
Which can be infinitely nested. I want to extract all of the comment information in a “flattened” format, just a list of usernames and the contents of their comment without worrying about the “level” of the comment. How would I do something like that using Javascript/JQuery?
use recursion:
a here – parsed JSON, b – result;
b structure is
{user1: [comment,comment,comment],user2: [] ...}http://jsfiddle.net/NkTst/1/
check http://jsfiddle.net/NkTst/2/ if you still need extended info on comments