-1

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
Krutarth Patel
  • 3,407
  • 6
  • 27
  • 54

2 Answers2

0

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.

zacks
  • 86
  • 5
0

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

backspace83
  • 342
  • 4
  • 10