Created
January 28, 2011 17:46
-
-
Save robballou/800633 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Got data from the web service | |
*/ | |
- (void)requestFinished:(ASIHTTPRequest *)request { | |
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; | |
// Use when fetching text data | |
NSString *responseString = [request responseString]; | |
// parse the response | |
SBJsonParser *parser = [SBJsonParser new]; | |
id content = [responseString JSONValue]; | |
if(!content){ | |
// parsing error | |
NSLog(@"%@", parser.errorTrace); | |
return; | |
} | |
/* | |
In my case, the data takes the form of an array of dictionarys: | |
[{...},{...}] | |
So content is an NSArray (or acts like one) and each node in there | |
is (or acts like) an NSDictionary. So I can run commands like this on | |
my parsed data: | |
[content count]; // how many items | |
// get the value for key in the 1st object | |
[[content objectAtIndex:0] objectForKey:@"key"]; | |
*/ | |
[pool release]; | |
} | |
/* | |
The async request to get new data failed | |
*/ | |
- (void)requestFailed:(ASIHTTPRequest *)request { | |
NSError *error = [request error]; | |
NSLog(@"%@", error); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment