0

愚蠢的问题。我只是将示例 AFNetworking 代码粘贴到:

NSURL *url = [NSURL URLWithString:@"https://gowalla.com/users/mattt.json"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];

AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
    NSLog(@"Name: %@ %@", [JSON valueForKeyPath:@"first_name"], [JSON valueForKeyPath:@"last_name"]);
} failure:nil];

[operation start];

但是,什么也没有发生。如果我向 NSLog 输出操作,看起来请求已被取消:

<AFJSONRequestOperation: 0x81655f0, state: isExecuting, cancelled: NO request: <NSURLRequest https://gowalla.com/users/mattt.json>, response: (null)>

我究竟做错了什么?

4

1 回答 1

0

您最好的选择是添加一个失败块,然后检查其中提供的变量

NSURL *url = [NSURL URLWithString:@"https://gowalla.com/users/mattt.json"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];

AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
    NSLog(@"Name: %@ %@", [JSON valueForKeyPath:@"first_name"], [JSON valueForKeyPath:@"last_name"]);
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
    NSLog(@"%@", [error localizedDescription]);
}];

[operation start];
于 2012-04-01T21:32:47.790 回答