3

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 = "Expected content type {(\n \"text/json\",\n \"application/json\",\n \"text/javascript\"\n)}, got text/html";

can somebody help me?

3 Answers 3

6

In my errorlog it prints "got text/html". So just add

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

It works.

Sign up to request clarification or add additional context in comments.

Comments

2
[AFJSONRequestOperation addAcceptableContentTypes:@"text/plain"]

The above is deprecated from AFNetworking 2.x. Instead you can call the following on the instance of the AFHTTPRequestOperation as follows

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

Where manager is your instance of AFHTTPRequestOperation.

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

1 Comment

Also, remember to use ?dl=1 instead of ?dl=0 so that text/plain content type is used for downloading json file.
1

Because the link you provide doesn't hotlink the file. It links to an HTML page to download the file. Try going there in a browser...

Try this link instead: https://dl.dropbox.com/s/qz16qyi3julygl9/facebook.json?dl=1 No guarantees it will work though. A lot of companies frown on directly linking to files in this way.

6 Comments

I instead the link you tell me. but I have same error again. I think this error may about NSLocalizedDescription = "Expected content type {(\n \"text/json\",\n \"application/json\",\n \"text/javascript\"\n)}, got text/plain"; thanks.
Then you need to find a way to link directly to it. You might not be able to with DropBox. However, that is the source of your problem. You might need to move it to another server, or use an API.
ahhhh I found that dropbox return content type of json file --> text/plain but AFJSONRequestOperator is support "text/json", "application/json", "text/javascript" how to represent content type in text/json ?
yippy, I have solved this problem. go in to AFJSONRequestOperation.m and edit method -> + (NSSet *)acceptableContentTypes; and add mime type -> @"text/plain" to NSSet
You can set the acceptable content type of individual operations to include text/plain. Or if you're using AFNetworking 1.0RC1, you can do [AFJSONRequestOperation addAcceptableContentTypes:@"text/plain"]
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.