0

Ia m getting an cocoa error 3840 when I am trying to serialize the JSON response and I am getting the following error message in the console "JSON text did not start with array or object and option to allow fragments not set." But i happened to check the response in chrome client and I get the correct response. And when I copy pasted the response in JSONValidator, I got it as a valid JSON. But in my iOS app I am somehow not able to get the response.

Is there a way to fix it from iOS code? I tried all possible solutions from internet.

NSError *error = nil;
NSMutableArray *jsons = [NSJSONSerialization JSONObjectWithData:theResponseData options:NSJSONReadingAllowFragments error:&error];
NSLog(@"connectionDidFinishLoading %@", jsons);

I tried MutableContainers, MutableLeaves and kNil in options of serialization. Still I am not able to fetch the data.

1 Answer 1

0

Try this - hope it will work

if ([operation isKindOfClass:[AFJSONRequestOperation class]] && [operation respondsToSelector:@selector(setJSONReadingOptions:)]) 
{    
    ((AFJSONRequestOperation *)operation).JSONReadingOptions = NSJSONReadingAllowFragments;
}

[httpClient enqueueHTTPRequestOperation:operation];

If it doesn't work then

[{"Firstname":"Johnny"}],

This is the only sample content your Web response should contain.

2
  • Do we need to import any framework for AFJSONRequestOperation? what is operation? And what is httpClient?
    – Leo Joseph
    Nov 28, 2014 at 12:55
  • send your sample JSON
    – User1075
    Dec 2, 2014 at 12:32

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.