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

iphone

please add : ios json parsing tutorial

2 Answers

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Amit Bijlani and I plan to cover that for iOS and Android soon! Check out the latest "Build a Blog Reader App" project and we'll get to that in January.

Hey Pankaj,

Its pretty simple. You just need to make use of NSJSONSerialization class to achieve it.

Here is a small example.

//specify the url of website

NSString *urlString=@"http://somewebsiteurl.com";

//perform url encoding for adding escape characters

NSString *urlEncoded = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

//convert this encoded string to NSURL format
NSURL *url=[NSURL URLWithString:urlEncoded];

//store the jsondata from the specified url into a NSData variable
NSData *jsonData=[NSData dataWithContentsOfURL:url];

if (jsonData) {

//If the url generated any json data we will use NSJSONSerialization class to convert it and store into our objectivec formatted NSArray

    NSMutableArray *sampleArray=[NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:&error];

}

Hope it helps!!! :)