Friday, 15 July 2011

ios5 - Pull out valueForKeys of an inner NSMutableDictionary iOS -



ios5 - Pull out valueForKeys of an inner NSMutableDictionary iOS -

ok , store json feed array called jsonarray. loop on jsonarray pulling out array keys , storing them strings. add together strings inner dictionary called innerdict, add together dictionary info dictionary key thepostcode using below. innerdict stored within infodict.

-(void)pointinfo{ infodict = [[nsmutabledictionary alloc]init]; (int = 0; < jsonarray.count; i++) { innerdict = [[nsmutabledictionary alloc]init]; info = [[jsonarray objectatindex:i]objectforkey:@"inf"]; thepostcode = [[jsonarray objectatindex:i]objectforkey:@"pc"]; mail service = [[jsonarray objectatindex:i]objectforkey:@"mail"]; url = [[jsonarray objectatindex:i]objectforkey:@"url"]; type = [[jsonarray objectatindex:i]objectforkey:@"items"]; [innerdict setobject:type forkey:@"items"]; [innerdict setobject:info forkey:@"info"]; [innerdict setobject:mail forkey:@"mail"]; [innerdict setobject:url forkey:@"url"]; [infodict setobject:innerdict forkey:thepostcode]; }

the output of infodict looks this:

infodict { "me14 4nn" = { info = ""; items = 4; mail service = ""; url = ""; }; "me15 6lg" = { info = af; items = "0,6,9"; mail service = ""; url = ""; }; "me15 6ye" = { info = ""; items = "4,5,6,7,11"; mail service = ""; url = ""; }; }

now want values of innerdict object i.e "me15 6ye" above , utilize query pull out associated info info, items, mail service , url keys. have been staring @ screen few hours not getting it.

i can pull out lastly object of inner dict using below grab values associated particular postcode innerdict key. brain fried @ moment!

for (nsmutabledictionary *dictionary in infodict) { nslog(@"url %@", [innerdict objectforkey:@"url"]); nslog(@"mail %@", [innerdict objectforkey:@"mail"]); nslog(@"items %@", [innerdict objectforkey:@"items"]); nslog(@"items %@", [innerdict objectforkey:@"info"]); }

to right inner dictionary, utilize objectforkey:

nsdictionary *innerdict = [infodict objectforkey:@"me15 6ye"]; nslog(@"url %@", [innerdict objectforkey:@"url"]); nslog(@"mail %@", [innerdict objectforkey:@"mail"]); nslog(@"items %@", [innerdict objectforkey:@"items"]); nslog(@"info %@", [innerdict objectforkey:@"info"]);

ios ios5 nsdictionary nsmutabledictionary key-value-coding

No comments:

Post a Comment