Ios – Error with AFNetworking for JSON Parsing

afnetworkingiosjson

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?

Best Answer

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

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

It works.