如何在没有"quot"的情况下转换JSON。


var text = [{"name":"en3","value":234},{"name":"en4","value":135},{"name":"en1","value":335},{"name":"en2","value":310},{"name":"en5","value":1548}]

如何转换为json没有"?

如:[{"name":"en3","value":234},等等?

我尝试使用JSON.parse('${resultData}'.replace(/"/g, '\"')),但它抛出错误Uncaught SyntaxError: Unexpected token

将您的regEx替换为/"/g, '"'

。代码应该是JSON.parse('${resultData}'.replace(/"/g, '"'))

var text = "[{"name":"en3","value":234},{"name":"en4","value":135},{"name":"en1","value":335},{"name":"en2","value":310},{"name":"en5","value":1548}]"

"从上面的字符串中移除

var text=text.replace(/"/g, '"');

然后解析文本数组为

var json=JSON.parse(text);

然后检查值为....

  for(var i=0;i<json.length;i++)
        { 
            console.log(json[i].name);
            console.log(json[i].value);
        }

删除\:

'${resultData}'.replace(/&quot;/g, '"')

更好的做法是:一开始就不要将"编码为&quot;