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
Hamish Irving
12,257 PointsTrouble with Blog Reader Data Not Displaying
Hi All,
I'm having some issues with: Build a Blog Reader iPhone App > Getting Data From the Web > Downloading and Parsing JSON Data
I am successfully downloading the data from the Treehouse blog and it displays in the console, however the data does not show up in the table view on the device.
The only thing I can think of is that the 'Posts' key in the JSON displayed in the console begins with a '(' rather than a '[' and that this is affecting the parsed data?
JSON as printed in console:
2013-06-17 19:11:46.907 BlogReaderII[39247:c07] {
count = 10;
"count_total" = 1418;
pages = 142;
posts = (
{
author = "Adam Clark";
date = "2013-06-17 09:30:47";
id = 21883;
thumbnail = "<null>";
title = "Projects Gone Bad Part 1: What Now?";
url = "http://blog.teamtreehouse.com/projects-gone-bad-part-1-what-now";
},
{
author = "Mat Helme";
date = "2013-06-14 10:20:36";
id = 21809;
thumbnail = "http://blog.teamtreehouse.com/wp-content/uploads/2013/06/windows8-150x150.png";
title = "Start a Style Movement by Designing a Flaw";
url = "http://blog.teamtreehouse.com/start-a-style-movement-by-designing-a-flaw";
},
{
author = Treehouse;
date = "2013-06-13 09:30:52";
id = 21877;
thumbnail = "<null>";
title = "Hiring People to Work With You featuring Paul Boag – Quick TIp";
url = "http://blog.teamtreehouse.com/hiring-people-to-work-with-you-featuring-paul-boag-quick-tip";
},
{
author = "Faye Bridge";
date = "2013-06-12 14:30:28";
id = 21874;
thumbnail = "http://blog.teamtreehouse.com/wp-content/uploads/2013/06/ewwiLuU-150x150.jpg";
title = "Dean’s List: Christoph Rumpel";
url = "http://blog.teamtreehouse.com/deans-list-christoph-rumpel";
},
{
author = "Jake Rocheleau";
date = "2013-06-12 09:30:49";
id = 21828;
thumbnail = "http://blog.teamtreehouse.com/wp-content/uploads/2013/06/01-happy-cog-fixed-navigation-topbar-150x150.png";
title = "Fixed Headers and Navigation Bars Used in Web Design";
url = "http://blog.teamtreehouse.com/fixed-headers-and-navigation-bars-used-in-web-design";
},
{
author = "Adam Clark";
date = "2013-06-11 14:30:32";
id = 21873;
thumbnail = "<null>";
title = "Avoid Cash-flow Problems Through Better Client Management";
url = "http://blog.teamtreehouse.com/avoid-cash-flow-problems-through-better-client-management";
},
{
author = Treehouse;
date = "2013-06-11 10:00:33";
id = 21872;
thumbnail = "<null>";
title = "SVG and Icon Fonts, Typography and CSS Sliders – Treehouse Show Ep 43";
url = "http://blog.teamtreehouse.com/svg-and-icon-fonts-typography-and-css-sliders-treehouse-show-ep-43";
},
{
author = "Matt West";
date = "2013-06-10 15:00:02";
id = 21788;
thumbnail = "http://blog.teamtreehouse.com/wp-content/uploads/2013/06/todo-app-screenshot1-150x150.png";
title = "Create Your Own To-Do App with HTML5 and IndexedDB";
url = "http://blog.teamtreehouse.com/create-your-own-to-do-app-with-html5-and-indexeddb";
},
{
author = "Mat Helme";
date = "2013-06-10 10:14:31";
id = 21805;
thumbnail = "<null>";
title = "The Four Golden Questions to a Successful Business";
url = "http://blog.teamtreehouse.com/the-four-golden-questions-to-a-successful-business";
},
{
author = Treehouse;
date = "2013-06-07 16:12:09";
id = 21827;
thumbnail = "<null>";
title = "Treehouse Launches Job Board";
url = "http://blog.teamtreehouse.com/treehouse-launches-job-board";
}
);
status = ok;
}
This appears to be invalid due to the substituted '('
Code from implementation file initialising tableView and pulling JSON from the Treehouse blog URL:
#import "TableViewController.h"
@interface TableViewController ()
@end
@implementation TableViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
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"];
}
Also see screenshot:
Any help is appreciated.
Thanks, Hamish
Hamish Irving
12,257 PointsHi James, sorry I thought the screenshot might suffice. Have edited post to include code.
Thanks, Hamish
2 Answers
Hamish Irving
12,257 PointsIt appears the JSON is not valid, due to the '(', but I have no idea why xcode would make this substitution?
Amit Bijlani
Treehouse Guest TeacherJust checked the URL in the browser and it looks fine. Have you defined your cellForRowAtIndexPath method?
Hamish Irving
12,257 PointsHi Amit,
Thanks for pointing me in this direction, I had defined cellForRowAtIndexPath but I had not changed the valueForKey string values being returned (I had "Title" and "Author" rather than "title" and "author")
All fixed, although I still find it confusing that xcode prints a "(" in the JSON in the console?
Thanks, Hamish
James Barnett
39,199 PointsIf you want to check to see if your JSON is valid check out JSON Lint

James Barnett
39,199 PointsJames Barnett
39,199 PointsMight help if you edit your original post to include your code.