AFNet 例子

NSMutableURLRequest *request = [self.hfClient requestWithMethod:@"GET" path:

@"http://9snow.org/weather/api?city=%E5%8C%97%E4%BA%AC"

parameters:nil];

[request setTimeoutInterval:30];

//

[AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"text/html"]];

AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON)

{

NSLog(@"json %@",[JSON class]);

_resultTextView.text = [NSString stringWithFormat:@"%@",JSON];

// do something with return data

}failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON)

{

// code for failed request goes here

NSLog(@"%@",[error description]);

_resultTextView.text = [NSString stringWithFormat:@"%@",JSON];


}];

operation.JSONReadingOptions = NSJSONReadingAllowFragments;

[operation start];


你可能感兴趣的:(net)