Created
March 9, 2013 03:51
-
-
Save yankchina/5122433 to your computer and use it in GitHub Desktop.
用AFNetworking库获取远端的JSON数据,其PHP文件需要增加 header('Content-type: application/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://localhost:8080/tce/testsuites/json-sample.php"]; | |
NSURLRequest *request = [NSURLRequest requestWithURL:url]; | |
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { | |
NSLog(@"success: %@",[JSON valueForKey:@"name"]); | |
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) { | |
NSLog(@"fail: %@", [error userInfo]); | |
}]; | |
[operation start]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment