objective c - how to parse this JSON in OBJ c -
i receive json string web process
{ "result":"ok", "description":"", "err_data":"", "data":[ { "id":"14d19a9b-3d65-4fe2-9ace-4c2d708daad8" }, { "id":"8bfd10b8-f5fd-4cee-a307-fe4382a0a7fd" } ] } and when use following data:
nserror *jsonerror = nil; nsdata *objectdata = [ret datausingencoding:nsutf8stringencoding]; nsdictionary *json= [nsjsonserialization jsonobjectwithdata: objectdata options:kniloptions error: &jsonerror]; nslog(@"data: %@",[json objectforkey:@"data"]); it gets logged as:
( { id = "14d19a9b-3d65-4fe2-9ace-4c2d708daad8"; }, { id = "8bfd10b8-f5fd-4cee-a307-fe4382a0a7fd"; } ) how can parse data nsdictionary value , keys?
the web returns object has property array of objects, so...
nsdictionary *json= // code nsarray *array = json[@"data"]; (nsdictionary *element in array) { nslog(@"%@", element); // or, digging little deeper nsstring *idstring = element[@"id"]; nslog(@"id=%@", idstring); }
Comments
Post a Comment