前端开发有时会遇到后端返回一个json字符串,但是他的json的内容是用单引号的,在使用JSON.parse进行转义的时候会报错,原因就是不能解析单引号的json格式,所以我们需要进行替换;
var action =
{'act':'href','val':'http://xxx'};
// 后台传过来的json字符串;
var newAction = action.replace(/'/g, '"');
//把单引号替换成双引号
//newAction:
{act: "href", val: "http://xxx"}