javascript - 删除转义字符

标签 javascript escaping

我正在使用一个返回 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/

相关文章:

c - 为什么我必须使用\x1b 而不是\来表示转义字符

vb.net - 在 VB.NET 中显示向下的三角形 ▼ (U+25BC)

html - 如何在 <pre> 标签内转义 < 和 >

javascript - 如何使用javascript在曲线上移动对象

javascript - 为什么当变量为 true 时 JavaScript 最后执行 DOM 语句?

javascript - 为什么字符串中包含 `&lt;script&gt;` 会导致 JS 语法错误?

java - 如何在 Java 中转义字符串?

javascript - javascript命名函数的范围是什么,作为参数传递

javascript - 如何在 Angular 页面中设置 CSRF token - OWASP CSRFGuard 3.0

javascript - HTML5 : readAsDataURL