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 Build a Blog Reader iPhone App Getting Data from the Web Downloading and Parsing JSON Data

Benjamin Stephens-Fripp
Benjamin Stephens-Fripp
1,482 Points

The titles come up but there is no author coming up

When I run the the simulation using the JSON data I have the titles come up correctly but I do not get any authors showing up in the subtitle part - and yes I do have the cell set up for subtitle view

4 Answers

Could you post the code you have written for setting the author to the subtitle of the cell?

Benjamin Stephens-Fripp
Benjamin Stephens-Fripp
1,482 Points

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"];

Is this the entire block of code you're using to extract the data from that URL? I don't see a HTTP request anywhere in there. Do this to fetch data and extract the data you need from the response:

  1. Set up whatever networking API you will use to communicate with the server. There are several good ones to use out there, but in this case, we'll use Apple's NSURLSession networking API
  2. Set up the URL endpoint
  3. Set up the HTTP request. In this case, you'll be using the "GET" method to fetch data from the server.
  4. Perform your request using NSURLSession's "NSURLSessionDataTask"
  5. Serialize the response data using NSJSONSerialization
  6. Parse the json and smile
NSURLSession *session = [NSURLSession sharedSession];
NSURL *blogURL = [NSURL URLWithString:@"http://blog.teamtreehouse.com/api/get_recent_summary/"];
NSURLRequest *request = [NSURLRequest requestWithURL:blogURL]; //the "GET" method is default so you don't have to explicitly define a request method
NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
        NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data option:kNilOptions error:&error];
//do your beautiful parsing here
    }
[task resume]; //make the magic happen
Benjamin Stephens-Fripp
Benjamin Stephens-Fripp
1,482 Points

It's ok there was another section of code that talked about what displayed in each section that I did not post. I realised this morning that in this section I had capitalised the word Author and it therefore didn't recognise the lower case version in the JSON file. Thanks for your help