JavaScript 中字符串转为Json对象出错的解决(转)
var text = '{a:"aa\r\nb\r\nb",b:"33"}'; var json = eval("(" + text + ")");// 报错:未结束的字符串常量 //正确 while (text.indexOf("\r") >= 0) { text = text.replace("\r", "\\r"); text = text.replace("\n", "\\n"); } var json = eval("(" + text + ")");