javascript - remove escaped character - Stack Overflow

I am working with a javascript function that returns a string of XML.However, within IE I get that st

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

Share Improve this question asked Oct 1, 2012 at 19:13 geo derekgeo derek 3952 gold badges5 silver badges17 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

Before 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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742277200a4413813.html

相关推荐

  • javascript - remove escaped character - Stack Overflow

    I am working with a javascript function that returns a string of XML.However, within IE I get that st

    1天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信