Parse multiple JSON in Objective C -
long story, short. need access parent in json file. how parse multiple json in objective-c? ) need access author > name json. (*removed link)
the code is:
nsurl *blogurl = [nsurl urlwithstring:@"*removed link"]; nsdata *jsondata = [nsdata datawithcontentsofurl:blogurl]; nserror *error = nil; nsdictionary *datadictionary = [nsjsonserialization jsonobjectwithdata:jsondata options:0 error:&error]; // nslog(@"%@",datadictionary); self.blogposts = [nsmutablearray array]; nsarray *blogpostsarray = [datadictionary objectforkey:@"posts"]; (nsdictionary *bpdictionary in blogpostsarray) { blogpost *blogpost = [blogpost blogpostwithtitle:[bpdictionary objectforkey:@"title"]]; blogpost.author = [bpdictionary objectforkey:@"author"]; blogpost.thumbnail = [bpdictionary objectforkey:@"thumbnail"]; blogpost.date = [bpdictionary objectforkey:@"date"]; blogpost.url = [nsurl urlwithstring:[bpdictionary objectforkey:@"url"]]; [self.blogposts addobject:blogpost]; }
how can make access value ?
you should able use dot notation
json
{ "author": { "name" : "mckeejm" } }
objective c:
blogpost.author = [bpdictionary valueforkeypath:@"author.name"];
updated @martin
Comments
Post a Comment