Skip to content

Instantly share code, notes, and snippets.

@yankchina
Created March 9, 2013 03:51
Show Gist options
  • Save yankchina/5122433 to your computer and use it in GitHub Desktop.
Save yankchina/5122433 to your computer and use it in GitHub Desktop.
用AFNetworking库获取远端的JSON数据,其PHP文件需要增加 header('Content-type: application/json');
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