Krutarth Patel
Krutarth Patel

Reputation: 3455

Error Domain=NSCocoaErrorDomain Code=3840 "Invalid escape sequence around character 746."

I am getting this error

Error Domain=NSCocoaErrorDomain Code=3840 "Invalid escape sequence around character 746." UserInfo={NSDebugDescription=Invalid escape sequence around character 746.}

Here is my code to parse JSON:

NSString *strResponse = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
strResponse=[self stringByRemovingControlCharacters:strResponse];
NSData *jsonData =  [strResponse dataUsingEncoding:NSUTF8StringEncoding];
responseObject = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&serializationError

Using this code I am getting response object in other API. but in my API contains HTML tags.

My issue is I am getting JSON string but it is not parsing in JSON. for this API I am getting error

"Error Domain=NSCocoaErrorDomain Code=3840".

My conclusion is that JSON is not parsing properly in above code.

Upvotes: -1

Views: 2248

Answers (2)

backspace83
backspace83

Reputation: 393

NSJSONSerialization throw an error if you try to escape ” character using \”. Only " need to be escaped

Upvotes: 0

zacks
zacks

Reputation: 84

The string from Ur backend may be invalid JSON,it may contain "\s""\n""\t" or other tab character。And in Xcode u print it will not see the tab character,the console will not print them.You may get the JSON and find if there are tab characters.

Upvotes: 0

Related Questions