I have a NSString containing possible unwanted characters that I have to convert to the escaped unicode version. More specifically, I need to pass a JSON object (serialized as a string) to a UIWebView via it’s script evaluation method, and some characters tend to raise a JS exception.
So I want to encode all characters mentioned to be unsafe by JSLint which are:
\u0000-\u001f
\u007f-\u009f
\u00ad
\u0600-\u0604
\u070f
\u17b4
\u17b5
\u200c-\u200f
\u2028-\u202f
\u2060-\u206f
\ufeff
\ufff0-\uffff
and replace them with their escaped equivalents.
What’s the best way to do this?
UPDATE: Somehow \u2028 (line separator char) snuck in the JSON
Well, it’s not exactly the solution I had in mind, but trimming is also a suitable option