1

When using AFNetwork (with JSONKit ), got a error:

Domain=JKErrorDomain Code=-1 "Illegal \u Unicode escape sequence." UserInfo=0x834cab0 {JKAtIndexKey=218, JKLineNumberKey=1, NSLocalizedDescription=Illegal \u Unicode escape sequence.}

Searching lets me know such details

Any fixs or workaround for this issue ?

Community
  • 1
  • 1
Forrest
  • 122,703
  • 20
  • 73
  • 107

1 Answers1

0

First you need to find out what the illegal sequence is.

If you cannot fix the web service to keep it from emitting bad data, then you will need to pre-process the response before evaluation the JSON.

In the source you cite, they use a simple regex s/[\u0000-\u001f]/\\uFFFD/g to invalidate all the raw ASCII characters less that 20. Depending on the invalid sequence you have, this might work for you also.

Jeffery Thomas
  • 42,202
  • 8
  • 92
  • 117
  • Just wonder why the famous JSONKit did not figure workaround for this. Thanks for your answer. – Forrest Jun 20 '12 at 05:38
  • These tools are written very conservatively now because loose Unicode parsing has been an attack vector used by hackers. Again to quote your own citation: "Dealing with malformed UTF8 isn't straightforward, and there's a lot of security issues that have been raised and addressed over the years. It's not clear to me that one can safely replace characters < 0x20 with U+FFFD, or do so without potentially introducing subtle security problems." – Jeffery Thomas Jun 20 '12 at 11:54