iPhone/iOS JSON parsing tutorial

IphoneObjective CIosJsonUitableview

Iphone Problem Overview


As a learning experience, I want to make an iPhone application that calls a webserver/webservice, retrieves a JSON response, and uses that response to populate the rows of a UITableView (assuming it converts the JSON into an NSArray first).

Anyone know of anything that might be useful?

Iphone Solutions


Solution 1 - Iphone

You will love this framework.

And you will love this tool.

For learning about JSON you might like this resource.

And you'll probably love this tutorial.

Solution 2 - Iphone

As of iOS 5.0 Apple provides the NSJSONSerialization class "to convert JSON to Foundation objects and convert Foundation objects to JSON". No external frameworks to incorporate and according to benchmarks its performance is quite good, significantly better than SBJSON.

Solution 3 - Iphone

SBJSON *parser = [[SBJSON alloc] init];

NSString *url_str=[NSString stringWithFormat:@"Example APi Here"];

url_str = [url_str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
      
NSURLRequest *request =[NSURLRequest requestWithURL:[NSURL URLWithString:url_str]];

NSData *response = [NSURLConnection sendSynchronousRequest:request  returningResponse:nil error:nil];

NSString *json_string = [[NSString alloc] initWithData:response1 encoding:NSUTF8StringEncoding]

NSDictionary *statuses = [parser2 objectWithString:json_string error:nil];

 NSArray *news_array=[[statuses3 objectForKey:@"sold_list"] valueForKey:@"list"];
   
    for(NSDictionary *news in news_array)
{

    @try {
        [title_arr addObject:[news valueForKey:@"gtitle"]];    //values Add to title array
        
    }
    @catch (NSException *exception) {
        
        [title_arr addObject:[NSString stringWithFormat:@""]];
    }
    

Solution 4 - Iphone

try out with this fastest JSON framework JSONKit. it's faster than normal JSON framework.

Solution 5 - Iphone

This is the tutorial I used to get to darrinm's answer. It's updated for ios5/6 and really easy. When I'm popular enough I'll delete this and add it as a comment to his answer.

http://www.raywenderlich.com/5492/working-with-json-in-ios-5

http://www.touch-code-magazine.com/tutorial-fetch-and-parse-json-in-ios6/

Solution 6 - Iphone

Here's a link to my tutorial, which walks you through :

  • creating a JSON WCF Web Service from scratch (and the problems you'll want to avoid)
  • adapting it to read/write SQL Server data
  • getting an iOS 6 app to use the JSON servies.
  • using the JSON web services with JavaScript

http://mikesknowledgebase.com/pages/Services/WebServices-Page1.htm

All source code is provided, free of charge. Enjoy.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCasey FlynnView Question on Stackoverflow
Solution 1 - IphoneTodd HopkinsonView Answer on Stackoverflow
Solution 2 - IphonedarrinmView Answer on Stackoverflow
Solution 3 - IphonechandrikaView Answer on Stackoverflow
Solution 4 - IphoneHirenView Answer on Stackoverflow
Solution 5 - IphonecloudsurfinView Answer on Stackoverflow
Solution 6 - IphoneMike GledhillView Answer on Stackoverflow