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 Adapting Data for Display Downloading and Displaying an Image

JSON data

I for some reason can't get the website from the app to display any other site other then the treehouse blog. I followed the Json data section and it works fine, but if I use this link "http://sophisticatedignorance.net/?json=1" which has all the same info as the treehouse blog, the app comes up blank. Any help will be greatly welcomed.

2 Answers

Stone Preston
Stone Preston
42,016 Points

you would have to modify your code to select the correct keys for this new JSON. the treehouse blog json data as different keys than the one you posted (it does have a title key, but not an author key)

the JSON data you posted has an array of posts in a key called "posts". so for your blogPosts array initialization it is the same as the treehouse blog, but if you want to display data from each blog post you have to use the correct keys. this new json has a title key, but it doesnt have an author key so we will use the date key. (the blogPost class used in the app has an author proeprty and a title property)

self.blogPostsArray = [dataDictionary objectForKey:@"posts"];
for (NSDictionary *bpDIctionary in self.blogPostsArray) {

BlogPost *blogPost = [BlogPost blogPostWithTitle:[bpDictionary objectForKey:@"title"]];
blogPost.author = [bpDictionary objectForKey:@"date"
}

if that doesnt work you would need to make sure you are downloading the JSON correctly

I changed the author key to date as you suggested, but it still comes up blank. How do I make sure I'm downloading Json data correctly? It works for the treehouse blog, is that not downloading it correctly? Or do you mean something all together different then what I'm thinking? Does it matter I'm trying to get JSON data from a WP blog?

Stone Preston
Stone Preston
42,016 Points

use NSLog to check each of your objects related to the JSON download. log your URL object, then the JSON dataobject, then the dataDictionary, then the blogPost array etc. see if anything comes back NULL.