Created
May 27, 2013 21:25
-
-
Save nickjshearer/5659166 to your computer and use it in GitHub Desktop.
Simple AFNetworking example with JSON
This file contains 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
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