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 trialKai Jackson
2,499 PointsDownloading 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
RASHU BHATNAGAR
Courses Plus Student 2,669 PointsIs 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
5,196 PointsJust 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
2,499 PointsYes, the NSLog statement prints the JSON data to the console. Thanks for the help
Kai Jackson
2,499 PointsYes, the NSLog statement prints the JSON data to the console. Thanks for the help
Sean Lee
5,196 PointsI'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"];