Follow LostMuser on Twitter

Monday, December 20, 2010

iOS HTTP JsonLoader

Here's a nice Json HTTP request loader that I built.

Download it now: JsonLoader.zip

It requires TouchJson, which you can get here: https://github.com/TouchCode/TouchJSON

Here's some example code:


#import "JsonLoader/JsonLoader.h"

@interface myClass {

}

@property (nonatomic, retain) JsonLoader *jsonLoader;

@end

...

@implementation myClass

- (id)init {

if(self = [super init]) {

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://api.crunchbase.com/v/1/company/google.js"]];

self.jsonLoader = [[[JsonLoader alloc] initWithRequest:request delegate:self] autorelease];
}

returns self;
}

- (void)jsonLoadedSuccessfully:(JsonLoader*)loader json:(id*)json {

NSLog(@"loaded json:%@", json};
}

- (void)dealloc {

self.jsonLoader = nil;

[super dealloc];
}

Edit: Updated it to handle Arrays and other Json types beyond just dictionaries

1 comments:

  1. Awesome. Am trying this code with FourSquare APIv2.

    ReplyDelete

Musing's Blog Viewer Webcam



(People reading the blog right now!)