javascript - var x = "[{'a':'xx'},{'b':'xxx'}]"; How to parse into json object in js
世界只因有你
世界只因有你 2017-07-05 11:03:23
0
3
1216

var x = "[{'a':'xx'},{'b':'xxx'}]";How to parse it into a json object in js

世界只因有你
世界只因有你

reply all(3)
学霸

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)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template