Skip to content

Instantly share code, notes, and snippets.

@robballou
Created January 28, 2011 17:46
Show Gist options
  • Save robballou/800633 to your computer and use it in GitHub Desktop.
Save robballou/800633 to your computer and use it in GitHub Desktop.
/*
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