admin管理员组文章数量:1332404
I am working with a javascript function that returns a string of XML. However, within IE I get that string of XML back with escape characters embedded in it e.g. a double quote is a \”
"
Instead of
"
Is there an easy way to remove the escaped character sequence items?
Thanks,
Derek
I am working with a javascript function that returns a string of XML. However, within IE I get that string of XML back with escape characters embedded in it e.g. a double quote is a \”
"
Instead of
"
Is there an easy way to remove the escaped character sequence items?
Thanks,
Derek
3 Answers
Reset to default 2Before trying to fix this, you should investigate which other characters are being replaced. For example, when you get a single \
in other browsers do you get \\
in IE?
If the standard C escapes are added, then JSON.parse
will convert sequences like \"
into "
, \\
into \
, \n
into a line-feed, etc.
'foo\\bar\nbaz"' === JSON.parse('"foo\\\\bar\\nbaz\\""')
JSON.parse
is supported natively on most recent browsers, and on IE specifically, back to IE 8. The relevant MSDN page says
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.
A similar question: Javascript - Replacing the escape character in a string literal explains how to replace a escape character. Maybe you could replace the escape character with empty quotes?
Use JavaScript's replace()
method.
jsFiddle:
var string1 = "This is a string with all the \\\" characters escaped";
document.write(string1); // outputs: This is a string with all the \" characters escaped
document.write("<br />");
string1 = string1.replace("\\", "");
document.write(string1); // outputs: This is a string with all the " characters escaped
本文标签: javascriptremove escaped characterStack Overflow
版权声明:本文标题:javascript - remove escaped character - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742277199a2445418.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论