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

Removing HTML Character Entity References

A bit beyond the scope of the lesson, but it bugs me that this looks so poor.

I believe in an ideal world the JSON source would just properly decode their characters... but in lieu of this I can't seem to find any classes/methods (outside of implementing my own) that would decode the characters on the iOS end.

Anyone else who noticed this issue, figure out a solution?

2 Answers

Stone Preston
Stone Preston
42,016 Points

I found an NSString Category that was in this post that might do the job.

Hey Stone,

Thanks for your reply. I found this post as well - and actually had tried importing the project into my own - but ended up running into some linker errors - which for now is a bit beyond my capability.

In case it is of interest to you, here is a snippet of what I was trying to do:

    // I had to change it to a mutable array so I could modify the children
    NSMutableArray *posts = self.blogPosts;
    self.blogPosts = dataDictionary [@"posts"];
    for (int i=0; i < posts.count; ++i)
    {
        // Capturing each blog post into variable "post"
        NSString *post = posts[i];
        // New variable to store all of the decoded items by using the stringByDecodingHTMLEntities method
        NSString *decodedPost = [post stringByDecodingHTMLEntities];
        // Replaces the blog post item if something was actually decoded
        if (![decodedPost isEqual:post])
            [posts replaceObjectAtIndex:i withObject:decodedPost];

    }

Anyway I'll probably table this project for a bit later!

Thanks,

Brandon