Cocoa error 3840 using JSON (iOS) Cocoa error 3840 using JSON (iOS) objective-c objective-c

Cocoa error 3840 using JSON (iOS)


Unless you pass the option NSJSONReadingAllowFragments to [NSJSONSerialization JSONObjectWithData:options:error:] the response from the server must be valid JSON with a top level container which is an array or dictionary.

for example:

    { "response" : "Success" }

P.S.If you want a mutable dictionary you must also include NSJSONReadingMutableContainers in your options.


It may possible that, the response from your server doesn't contain valid JSON.

Technically, The JSON object must be start with either an "array" or an "object (dictionary)".

So, Whatever your server is returning isn't.

And, you can force the JSON to be consumed regardless by using the NSJSONReadingAllowFragments option.

by using ,

AFJSONResponseSerializer *responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments];


You can get this issue if you're connected to VPN on your iOS device.