Error with AFNetworking for JSON Parsing

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 a Request Error with the following error message:

NSErrorFailingURLKey = " https://www.dropbox.com/s/qz16qyi3julygl9/facebook.json "; NSLocalizedDescription = "Estimated content type {(\ n \" text / json \ ", \ n \" application / json \ ", \ n \" text / javascript \ "\ n)}, received text / html";

Can someone help me?

+3
source share
3 answers

In my error log it prints "got text / html". Therefore just add

[AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"text/html"]]

He works.

+6
source
[AFJSONRequestOperation addAcceptableContentTypes:@"text/plain"]

AFNetworking 2.x. AFHTTPRequestOperation

manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];

- AFHTTPRequestOperation.

: https://github.com/AFNetworking/AFNetworking/issues/1381

+2

Because the link you provide does not support the link to the file. It links to an HTML page for downloading a file. Try going there in your browser ...

Try using this link: https://dl.dropbox.com/s/qz16qyi3julygl9/facebook.json?dl=1 There is no guarantee that it will work. Many companies frowned, direct link to files this way.

+1
source

All Articles