Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Build a Blog Reader iPhone App Getting Data from the Web Downloading and Parsing JSON Data

Kai Jackson
Kai Jackson
2,499 Points

Downloading and Parsing JSON Data

I have closely followed the video, I have downloaded the extension for chrome i have entered the code, there are no errors. When i run the app it loads up with a table view with no content, it doesn't log the JSON code either. Here is my code...

NSURL *blogURL = [NSURL URLWithString:@"http://blog.teamtreehouse.com/api/get_recent_summary/"];

NSData *jsonData = [NSData dataWithContentsOfURL:blogURL];

NSError *error = nil;

NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];

NSLog(@"%@",dataDictionary);



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

5 Answers

Is it printing the NSLog statement in the console.... if yes then for now you are good... U will further have to parse the contents of the data dictionary into an array , ie create an array and store each post (which is in the data dictionary post) and then display each of the post as an element on the tableview...

Hope I am not wrong and this answer helps you in further understanding the blog reader project...

Sean Lee
Sean Lee
5,196 Points

Just debugged my own problem. May this this will help:

make sure "author" and "title" are all lower case. I had it capitalized so it wasn't showing anything in the simulator.

  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    // Configure the cell... NSDictionary *blogPost = [self.blogPosts objectAtIndex:indexPath.row];

    cell.textLabel.text = [blogPost valueForKey:@"title"]; cell.detailTextLabel.text = [blogPost valueForKey:@"author"]; return cell; }

Kai Jackson
Kai Jackson
2,499 Points

Yes, the NSLog statement prints the JSON data to the console. Thanks for the help

Kai Jackson
Kai Jackson
2,499 Points

Yes, the NSLog statement prints the JSON data to the console. Thanks for the help

Sean Lee
Sean Lee
5,196 Points

I'm facing the same problem, it prints in the console just like Amit's example but nothing is being loaded in the simulator.

NSURL *blogURL = [NSURL URLWithString:@"http://blog.teamtreehouse.com/api/get_recent_summary"];
NSData *jsonData = [NSData dataWithContentsOfURL:blogURL];
NSError *error = nil;

NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error: &error];

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