Replace escaped single quote with single quote
I have a service returning results as JSON string with escaped single quote. Ex: O\\\'Neill开发者_高级运维
. Now, when displaying I need to unescape it to say O'Neill
. I have tried replacing the string but doesn't work and it throws a script error - Expected ")" when I tried to assign the text (HTML) to a DIV.
I'm just practicing my psychic powers here...but is your code trying to replace "\"
with ""
? If so, remember, you'll need to escape the backslash (as it's the escape char in Javascript). Try replacing "\\"
instead.
As mentioned up in the comments, though, the best fix would be to the service. There should be no need for \'
in JSON (and in fact, it's technically not even valid JSON), as the values should be double-quoted (making it unnecessary to escape a single quote).
Rather than escape it server side, why not replace it with the HTML entity '
?
精彩评论