Skip to content

Instantly share code, notes, and snippets.

@nickjshearer
Created May 27, 2013 21:25
Show Gist options
  • Save nickjshearer/5659166 to your computer and use it in GitHub Desktop.
Save nickjshearer/5659166 to your computer and use it in GitHub Desktop.
Simple AFNetworking example with JSON
NSURL *url = [NSURL URLWithString:@"http://content.guardianapis.com/search?format=json"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
// Prepare the operation with completion handlers
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSLog(@"Latest stories: %@", [JSON valueForKeyPath:@"response.results"]);
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON){
NSLog(@"There was a problem: %@", [error localizedDescription]);
}];
// Start the download asynchronously
[operation start];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment