AFNetworking for JSON解析出错

Kia*_*rom 3 json ios afnetworking

我有以下JSON解析代码:

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];
Run Code Online (Sandbox Code Playgroud)

但我有Request Failure并出现以下错误消息:

NSErrorFailingURLKey =" https://www.dropbox.com/s/qz16qyi3julygl9/facebook.json "; NSLocalizedDescription ="预期内容类型{(\n \"text/json \",\n \"application/json \",\n \"text/javascript \"\n)},得到text/html";

有人能帮助我吗?

小智 6

在我的错误日志中,它打印" got text/html ".所以只需添加

[AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"text/html"]]
Run Code Online (Sandbox Code Playgroud)

有用.