0

我继承了一个项目,正在实施 AFNetworking 并阅读文档,这听起来很棒,而且比当前代码简单得多。我有一个带有 json 数据的 url,所以我正在执行以下操作,但是得到了失败块并且不知道为什么。我确定它在那里,但我如何深入研究 AF 并记录响应以确定失败原因。我知道 url 有效,但也许它点击了 url 但解析有问题?

NSString *listURL = [NSString stringWithFormat:GET_LIST,BASE_URL];
NSURL *url = [NSURL URLWithString:briefListURL];
NSURLRequest *request = [NSURLRequest requestWithURL:url];

AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest: request
                                                                                        success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
                                                                                            self.list = [NSArray arrayWithArray:(NSArray *)JSON];                                                                                                    
                                                                                        } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
                                                                                            [self listOperationDidFail];
                                                                                        }];
4

1 回答 1

0

感谢@Larme这工作:

failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) { NSLog(@"Error: %@", error); }

另外,用文本/纯文本回答我自己的问题。只需在设置操作之前添加它:

  [AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"text/plain"]];
于 2013-09-18T17:14:39.157 回答