我正在使用一个返回 XML 字符串的 JavaScript 函数。然而,在 IE 中,我得到了 XML 字符串,其中嵌入了转义字符,例如双引号是\”
”
代替
”
有没有简单的方法来删除转义字符序列项?
谢谢,
德里克
最佳答案
在尝试解决此问题之前,您应该调查哪些其他字符被替换。例如,当您在其他浏览器中得到单个 \
时,您在 IE 中也会得到 \\
吗?
如果添加了标准 C 转义,则 JSON.parse
会将 \"
等序列转换为 "
、\\
变为 \
,\n
变为换行符,等等
'foo\\bar\nbaz"' === JSON.parse('"foo\\\\bar\\nbaz\\""')
JSON.parse
在大多数最新的浏览器上都受到 native 支持,特别是在 IE 上,可追溯到 IE 8。relevant MSDN page说
Supported in the following document modes: Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards. Also supported in Windows Store apps. See Version Information.
Not supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards.
关于javascript - 删除转义字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12679521/