我正在尝试在 Objective-C 中解析 JSON,但遇到了麻烦。我正在关注的教程中的示例仅进入父节点之后的第一级。我正在尝试获取更深入的数据。关于如何做到这一点的任何建议?
我要获取的元素: 标题:data.children[i].data.title 缩略图:data.children[i].data.thumbnail Json:http ://www.reddit.com/r/HistoryPorn/.json
NSURL *blogURL = [NSURL URLWithString:@"http://www.reddit.com/r/HistoryPorn/.json"];
NSData *jsonData = [NSData dataWithContentsOfURL:blogURL];
NSError * error = nil;
NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
self.blogPosts = [NSMutableArray array];
NSArray * blogPostsArray = [dataDictionary objectForKey:@"data"];
for (NSDictionary *bpDictionary in blogPostsArray) {
BlogPost * blogPost = [BlogPost blogPostWithTitle:[bpDictionary objectForKey:@"title"]];
blogPost.thumbnail = [bpDictionary objectForKey:@"thumbnail"];
blogPost.url = [NSURL URLWithString:[bpDictionary objectForKey:@"url"]];
[self.blogPosts addObject:blogPost];
}