使用正则表达式删除引号。
例如,如果它是一个 json 字符串,您可以这样做:
var json = '{ "name": "John Smith" }'; //Let's say you got this
json = json.replace(/\"([^(\")"]+)\":/g,"$1:"); //This will remove all the quotes
json; //'{ name:"John Smith" }'
如果您输入:
var a ='[{"data":[{"x":87.6,"y":85},{"x":116.08,"y":61},{"x":113.11,"y":49},{"x":181.37,"y":65},{"x":138.14,"y":74},{"x":66.03,"y":89}]}]';
a = a.replace(/\"([^(\")"]+)\":/g,"$1:");
a; //"[{data:[{x:87.6,y:85},{x:116.08,y:61},{x:113.11,y:49},{x:181.37,y:65},{x:138.14,y:74},{x:66.03,y:89}]}]"