AFNetworking进行JSON解析时出错 [英] Error with AFNetworking for JSON Parsing
本文介绍了AFNetworking进行JSON解析时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我具有以下用于JSON解析的代码:
I have the following code for JSON Parsing:
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.dropbox.com/s/qz16qyi3julygl9/facebook.json"]];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSLog(@"Request Success %@",[JSON class]);
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
NSLog(@"Request Failure Because %@",[error userInfo]);
}];
[operation start];
但我遇到请求失败,并显示以下错误消息:
but I have Request Failure with the following error message:
NSErrorFailingURLKey = https:// www。 dropbox.com/s/qz16qyi3julygl9/facebook.json ;
NSLocalizedDescription =预期的内容类型{(\n \ text / json\,\n \ application / json\,\n \ text / javascript\ \n)},得到了text / html;
NSErrorFailingURLKey = "https://www.dropbox.com/s/qz16qyi3julygl9/facebook.json"; NSLocalizedDescription = "Expected content type {(\n \"text/json\",\n \"application/json\",\n \"text/javascript\"\n)}, got text/html";
有人可以帮助我吗?
推荐答案
在我的错误日志中,它显示 忘记文字/ html 。因此,只需添加
In my errorlog it prints "got text/html". So just add
[AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"text/html"]]
有效。
这篇关于AFNetworking进行JSON解析时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文