Reputation: 1109
I am trying to link to a thumbnail image stored on a server using JSON. The code I have so far is:
NSArray *blogPostsArray = [dataDictionary objectForKey:@"posts"];
for (NSDictionary *bpDictionary in blogPostsArray) {
BlogPost *blogPost = [BlogPost blogPostWithTitle:[bpDictionary objectForKey:@"title"]];
blogPost.thumbnail = ???
//blogPost.date = [bpDictionary objectForKey:@"date"];
[self.blogPosts addObject:blogPost];
}
As you can see where the 3 question marks are is where I am stuck. Here is the JSON file I am working from, I need to know how to get down to the thumbnail url and assign it to blogPost.thumbnail
:
Upvotes: 0
Views: 83
Reputation: 119041
Try using key path navigation:
NSArray *attachments = [bpDictionary objectForKey:@"attachments"];
if (attachments.count > 0) {
blogPost.thumbnail = [attachments[0] valueForKeyPath:@"images.thumbnail.url"];
}
Upvotes: 1