APEX - Parsing a recursive JSON -


i programming salesforce (apex). input complex , recursive json.

{     "id":"0",     "children":[         {             "id":"1",             "children":[...]         },         {             "id":"2",             "children":[...]         }     ] } 

i need way iterate complex , recursive json (in apex).

anyone can help?

thanks,

hagai

if know names of attributes in json object, can create classes represent them , deserialize. instance:

public class myobject {   public string id;   public list<myobject> children; } 

then write method returns children

static list<myobject> getchildren(myobject parent){     list<myobject> children = new list<myobject>();     ( myobject c : parent.children ){         children.addall( getchildren(c) );         children.add(c);     }     return children; } 

and put 2 together:

myobject parent = (myobject)json.deserialize(jsonstring,myobject.class); list<myobject> = new list<myobject>(); all.add(parent); all.addall(getchildren(parent)); 

Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -