0

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.

Umer Hassam
  • 1,332
  • 5
  • 23
  • 42
  • 1
    We really need to see the JSON. – Avi Nov 12 '15 at 11:08
  • The JSON does have long decimal numbers like ** requestTime":0.084980964660645** could this be effecting the output? (http://stackoverflow.com/questions/18650365/valid-json-but-cocoa-error-3840-from-afnetworking-nsjsonserialization) ??? and if so how can I get around it? – Umer Hassam Nov 12 '15 at 11:08
  • JSON: https://docs.google.com/document/d/1rC_--QiS85A82L2AohuqjC0JWIgVEAj68i7UUOxpvMw/edit?usp=sharing – Umer Hassam Nov 12 '15 at 11:09
  • 1
    I ran a test, and the number you give as an example doesn't cause any problem. – Avi Nov 12 '15 at 11:19
  • Thanks for test so quick... I guess there must be some other issue :/ – Umer Hassam Nov 12 '15 at 11:24
  • 1
    I ran another test with the JSON you linked to, and it worked as expected. I am running on the command line, compiling for x64, not ARM. That may make a difference, but I don't see any errors. – Avi Nov 12 '15 at 11:27
  • hmmm... why would the architecture make a difference in JSON serialization... but if you're not getting an error then there must be some correlation... can you share the code you're running to test it?? there might be some clue we can find in there???... – Umer Hassam Nov 12 '15 at 11:34
  • `@import Foundation; int main(int argc, char **argv) { NSError *localError; NSString *s = [NSString stringWithContentsOfFile:@"x" encoding:NSUTF8StringEncoding error:NULL]; NSData *json = [s dataUsingEncoding:NSUTF8StringEncoding]; NSDictionary *d = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingAllowFragments error:&localError]; NSLog(@"%@\n\n%@", d, localError); return 0; }` – Avi Nov 12 '15 at 11:40
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/94919/discussion-between-avi-and-umer-hassam). – Avi Nov 12 '15 at 11:53

0 Answers0