Saturday 15 August 2015

How to parse multiple json in objective-c? -


I'm trying to parse JSON in Object-C but troubles are occurring. In the tutorial, I only go to the first level after the parent node. I am trying to get the data that is a bit darker. Any advice on how to do this?

Elements I'm trying to achieve: Title: Data. Child [i] .data.title thumbnail: data. Children [i] .data. Thumbnail Jason:

  NSURL * blogURL = [NSURL URL YouthString: @ "http://www.reddit.com/r/HistoryPorn/.json"]; NSData * jsonData = [NSData dataWithContentsOfURL: blogURL]; NSError * Error = Zero; NSDictionary * dataDictionary = [NSJSONSerialization JSONObjectWithData: jsonData Option: 0 Error: & amp; Error]; Self.blogPosts = [NSMutableArray array]; NSArray * blogPostsArray = [dataDictionary objectForKey: @ "data"]; (Blogpost ARRA for Nucleus * BPNation) {blogpost * blogpost = [blog post blog post entitled: [Bipedender ObjectForcae: @ "title"]]; BlogPost.thumbnail = [bpDictionary objectForKey: @ "thumbnail"]; BlogPost.url = [NSURL URLWithString: [bpDictionary objectForKey: @ "url"]]; [Self.blogPosts addObject: blogPost]; } {/ Code>   

With the new syntax, obtaining keys in nested dictionaries should be easy By drawing the tree, you can learn full keys / indexed path, remember that a dictionary starts with braces, and an array starts with brackets. For example, for the first entry in the children's array, retrieve the "thumbnail" and "url" value:

  NSDRIATION * JASON = [NSJSNEsationalization JSONObjectWithData: jsonData option: 0 error: and Error] ; If (! Json) {// always handles the final errors: NSLog (@ "% @", error); Return; } NSString * thumbnail = json [@ "data"] [@ "children"] [0] [@ "data"] [@ "thumbnail"]; NSString * url = json [@ "data"] [@ "children"] [0] [@ "data"] [@ "url"];    

No comments:

Post a Comment