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 trial8 Answers
Steve Hunter
57,712 PointsHi Shaun,
I've had a quick look through the code and the only thing that stands out to me are the capital letters at the beginning of each valueForKey:
key. JSON is pretty strict on spelling so the key must match precisely.
Try amending the lines to:
//setting the text of the cell and retrieving the titles from the NSDictionary
cell.textLabel.text = [blogPost valueForKey:@"title"];
//setting the detailed text of the cell and reteiveing the authors of the NSDictionary
cell.detailTextLabel.text = [blogPost valueForKey:@"author"];
So, that's changing Author to author and Title to title.
I may be wrong but that's worth a try at first. If you get no joy, we need to make sure that you have retrieved some JSON, then work out why it isn't getting to where it should be.
Keep me posted!
Steve.
Caleb Kleveter
Treehouse Moderator 37,862 PointsStone Preston , Amit Bijlani , and Steve Hunter , could you help Shaun with his code?
Caleb Kleveter
Treehouse Moderator 37,862 PointsYes you will need internet access to retrieve json data as it opens a web page in the default web browser.
Shaun Kelly
5,648 PointsMy code isn't working can you have a look please ?
- (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];
self.blogPosts = [dataDictionary objectForKey:@"posts"];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return [self.blogPosts count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//creating a cell object that can be reused
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
//creating a NSDicationary object for the cells
NSDictionary *blogPost = [self.blogPosts objectAtIndex:indexPath.row];
//setting the text of the cell and retrieving the titles from the NSDictionary
cell.textLabel.text = [blogPost valueForKey:@"Title"];
//setting the detailed text of the cell and reteiveing the authors of the NSDictionary
cell.detailTextLabel.text = [blogPost valueForKey:@"Author"];
//returning the cell object
return cell;
}
Caleb Kleveter
Treehouse Moderator 37,862 PointsWhat is your error and what video are you on for that code? The same one you posted your first question on?
Shaun Kelly
5,648 PointsThere is no information being displayed in my tables views but it still runs. And yes same video.
Caleb Kleveter
Treehouse Moderator 37,862 PointsVery strange, I'm not sure what is wrong with it, you could ask Stone Preston, Steve Hunter, and Amit Bijlani if you know how to do so on the forums, and if you do please let me know.
Shaun Kelly
5,648 Pointshow do I do that ?
Caleb Kleveter
Treehouse Moderator 37,862 PointsShaun, to tag somebody type the @ symbol and the start typing there name, you will see a list appear, select the person you want, you might notice that there is no highlight, don't worry, when you post it it will be.
Caleb Kleveter
Treehouse Moderator 37,862 PointsI'm not really sure, on occasion I see a name highlight in blue as if is a link, I suppose that it has to do with asking somebody, but I'm not sure how it is done, you could always post a question on the forums about it.
Shaun Kelly
5,648 Pointshey thanks it worked
Steve Hunter
57,712 PointsExcellent - glad to help!
Steve.