var x = "[{'a':'xx'},{'b':'xxx'}]";How to parse it into a json object in js
Idea: This is a non-standard json, first standardize it, for example, replace ' with ".
'
"
var x = "[{'a':'xx'},{'b':'xxx'}]"; x = x.replace(/[']/g, '"'); var obj = JSON.parse(x); console.log(x, obj);
Effect
zhaojunlike@zhaojunlike-winos MINGW64 ~/Desktop $ node demo.js [{"a":"xx"},{"b":"xxx"}] [ { a: 'xx' }, { b: 'xxx' } ]
x = JSON.stringify(x);JSON.parse(x);
const obj = JSON.parse(x)
Idea: This is a non-standard json, first standardize it, for example, replace
'
with"
.Effect
x = JSON.stringify(x);
JSON.parse(x);