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

2.2k Views Asked by At

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.

2

There are 2 best solutions below

0
On

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.

0
On

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