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.


Downloading and Parsing JSON Data

Hi guys i am referring to this video: http://teamtreehouse.com/library/build-a-blog-reader-iphone-app-2/getting-data-from-the-web/downloading-and-parsing-json-data-2

It is regarding the extra credit question. I am some how not able to get what are they asking to be displayed on the blog reader table view . I did every thing as i was taught and the app uptil now in the simulator works just fine. But the extra credit question i am not able to get what exactly they want us to do. Please help

3 Answers

Thanks Natacha S. for the prompt reply.

This is what i am doing in the - (void)viewDidLoad method. and I am still not able to get what am i doing wrong.

 NSURL *blogURL=[NSURL URLWithString:@"https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=JSON"];
    NSData *jsonData=[NSData dataWithContentsOfURL:blogURL];
//  NSLog(@"%@",jsonData);
    NSError *error=nil;

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

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

The app is working fine in the simulator, i mean there are no errors. but no data is showing on the table view in simulator.

Please help...

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

You have to look at the structure of the data that is presented to you.

    "responseData": {
        "results": [
                "GsearchResultClass": "GwebSearch",
                "unescapedUrl": "http://www.json.org/",
                "url": "http://www.json.org/",
                "visibleUrl": "www.json.org",
                "cacheUrl": "http://www.google.com/search?q=cache:l_yxMvC_ErgJ:www.json.org",
                "title": "<b>JSON</b>",
                "titleNoFormatting": "JSON",
                "content": "<b>JSON</b> (JavaScript Object Notation) is a lightweight data-interchange format. It is \neasy for humans to read and write. It is easy for machines to parse and generate."
                "GsearchResultClass": "GwebSearch",
                "unescapedUrl": "http://www.json.org/js.html",
                "url": "http://www.json.org/js.html",
                "visibleUrl": "www.json.org",
                "cacheUrl": "http://www.google.com/search?q=cache:y1JKLz1ap_IJ:www.json.org",
                "title": "<b>JSON</b> in JavaScript",
                "titleNoFormatting": "JSON in JavaScript",
                "content": "<b>JSON</b> is a subset of the object literal notation of JavaScript. Since <b>JSON</b> is a \nsubset of JavaScript, it can be used in the language with no muss or fuss."
        "cursor": {
            "resultCount": "4,100,000",
            "pages": [
                    "start": "0",
                    "label": 1
            "estimatedResultCount": "4100000",
            "currentPageIndex": 0,
            "moreResultsUrl": "http://www.google.com/search?oe=utf8&ie=utf8&source=uds&start=0&hl=en&q=JSON",
            "searchResultTime": "0.12"
    "responseDetails": null,
    "responseStatus": 200

As you can see above you have a dictionary which contains a key called responseData within that you have the results. So you can't directly access the results. You would need to use the method valueForKeyPath.

    self.blogPosts = [dataDictionary valueForKeyPath:@"responseData.results"];

They want you to use a different set of data to import into your blog reader. For example they'd like to see the data returned by a random google search, that you determine by modifying what comes after the "q="

Thanks for replying back Amit. It works fine now.... Thanks once again