[url]http://blog.objectgraph.com/index.php/2010/02/24/how-to-use-touch-json-and-sbjson/[/url]
[url]http://stackoverflow.com/questions/286087/best-json-library-to-use-when-developing-an-iphone-application[/url]
I will show how to use each of these libraries to decode JSON code in this post.
Touch JSON:
Include the following in your header
#import "CJSONDeserializer.h"
SB JSON:
The thing i like about SBJSON is it adds functions directly into NSString to get NSDictionary or NSArray objects when deserializing JSON strings.
Start with including the following header
Then you can simply use the following code
Please remember stringWithContentsOfURL has been deprecated so I would not recommend using it. We also just include the entire source of the specific JSON library when building our apps.
[url]http://stackoverflow.com/questions/286087/best-json-library-to-use-when-developing-an-iphone-application[/url]
I will show how to use each of these libraries to decode JSON code in this post.
Touch JSON:
Include the following in your header
#import "CJSONDeserializer.h"
NSString *twitterTrendsUrl=@"http://search.twitter.com/trends.json";
NSData *flickrData=
[NSData dataWithContentsOfURL:[NSURL URLWithString:twitterTrendsUrl]];
NSError *theError = nil;
id theObject =
[[CJSONDeserializer deserializer] deserialize:flickrData error:&theError];
NSLog(@"Error: %@", theError);
NSLog(@"Result: %@", theObject);
SB JSON:
The thing i like about SBJSON is it adds functions directly into NSString to get NSDictionary or NSArray objects when deserializing JSON strings.
Start with including the following header
#import "JSON.h"
Then you can simply use the following code
NSString *twitterTrendsUrl=@"http://search.twitter.com/trends.json";
NSString *output=
[NSString stringWithContentsOfURL:[NSURL URLWithString:twitterTrendsUrl]];
id theObject= [output JSONValue];
NSLog(@"%@",theObject);
Please remember stringWithContentsOfURL has been deprecated so I would not recommend using it. We also just include the entire source of the specific JSON library when building our apps.