Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Displaying Google JSON

I've tried to do the extra credit exercise for the "Getting Data From Web" stage and I just can't find out why my code isn't working. Check the google JSON return: http://d.pr/i/RhGJ

NSURL *blogURL = [NSURL URLWithString:@"https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=Design"];
//I've put the results array, not sure if that responseData affects something
self.blogPosts = [dataDictionary objectForKey:@"results"];

and here to add it into my cell

cell.textLabel.text = [blogPost valueForKey:@"titleNoFormatting"];
cell.detailTextLabel.text = [blogPost valueForKey:@"content"];

Did anyone was able to do this exercise? Do you know what's the problem on my code?

2 Answers

Thomas Anthony
seal-mask
.a{fill-rule:evenodd;}techdegree
Thomas Anthony
iOS Development Techdegree Student 22,352 Points

The reason you are having this issue is because you are trying to access an object with an undefined key: results. You need to access the result array within the responseData object like so:

self.blogPosts = [[dataDictionary objectForKey:@"responseData"] objectForKey:@"results"];

or

self.blogPosts = dataDictionary[@"responseData"][@"results"];

i had the same problem and now it solved. thanks Thomas Anthony.