The operation couldn’t be completed. (Cocoa error 3840.) for valid JSON

时间:2015-11-12 11:07:04

标签: ios objective-c json cocoa

I'm trying to resolve the Cocoa error 3840 for a couple hours now. I've read all the answers posted here on stackoverflow and on any other sources I could find but nothing seems to help...

The problem is that I know this error occurs when there is something wrong with the JSON object you receive from the server but the JSON I'm receiving is valid. I've tested it on multiple JSON validators online and its checks out every time.

Here's my code:

NSError *localError = nil;

NSDictionary *parsedObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&localError];

if (localError != nil) {
    NSLog(@"%@", [localError localizedDescription]);
} else {

    //NSDictionary *dict = [parsedObject objectForKey:@"status"];
    //NSLog(@"%@", [dict objectForKey:@"message"]);

}

return parsedObject;

Heres a google drive link to the JSON: https://docs.google.com/document/d/1rC_--QiS85A82L2AohuqjC0JWIgVEAj68i7UUOxpvMw/edit?usp=sharing

This error only occurs for some responses that i get from the server. The same code works fine for other links from the same API.

I've tried this with NSArray instead of NSDictionary thinking that maybe the server might be serving an array instead of a hash, also tried changing the option value for JSONObjectWithData:data:options:error method but as you can guess nothing worked.

I'll greatly appreciate any help I can get.

0 个答案:

没有答案