我继承了一个项目,并且正在实现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];
}];发布于 2013-09-18 17:14:39
多亏了@Larme,这个方法奏效了:
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) { NSLog(@"Error: %@", error); }另外,用文本/纯文本来回答我自己的问题。只需在设置操作之前添加以下内容:
[AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"text/plain"]];https://stackoverflow.com/questions/18877525
复制相似问题