取消捕获“;在javascript中

unescaping " in javascript

本文关键字:javascript 取消      更新时间:2023-09-26

我得到一个返回给我的JSON对象,如下所示:

result: {
 image: "..."
 title: "text text '"text'""
}

我使用underscore.js来渲染模板,但是当它显示标题时,它在文本中包含''"。

例如text text''"text''"

如何在显示前取消显示双引号?

感谢

.replaces可以做到:

text = result.text.replace(/''([''"])/g, '$1');

这个链接可能会有所帮助,但我在你的评论中看到,你得到的数据与你提到的完全相同,所以:

var result = { image: "...", title: "text text '"text'"" }
alert (result.title.toString().replace(/"/g, ''));