ios - Parsing JSON in Objective C with key names as incremented integers -
not sure how word question have json need parse formatted so:-
"nodes": { "4": { "node_id": 4, "title": "title 1", "description": "", }, "7": { "node_id": 7, "title": "title 2", "description": "", }, "12": { "node_id": 12, "title": "title 3", "description": "", },
normally grab values standard [dictionary objectforkey@"key"] items begin integer (string) finding hard parse correctly. missing simple here?
if want access 1 value following.
// assume jsonobject "root" dictionary nsdictionary *fourdictionary = jsonobject[@"nodes"]["4"] // object "4":{}
now if json in question can have dynamic number of objects trickier. easiest solution provider of json rewrite array of objects. object want using object's node_id value.
if not possible attempt right loop loop through of keys in "nodes" object , access items dictionary way.
i.e.
nsmutablearray *arrayofnodes = [nsmutablearray array]; nsdictionary *nodes = jsonobject[@"nodes"]; for(nsstring *numberkey in [nodes allkeys]) { nsdictionary *nodeobject = nodes[numberkey] [arrayofnodes addobject:nodeobject]; } // else nodes in array.
Comments
Post a Comment