我正在对像 {'foo': 'bar'}
如何将字符串转回对象?
最佳答案
您需要 JSON.parse()
您的有效 JSON 字符串。
var str = '{"hello":"world"}';
try {
var obj = JSON.parse(str); // this is how you parse a string into JSON
document.body.innerHTML += obj.hello;
} catch (ex) {
console.error(ex);
}
https://stackoverflow.com/questions/11171746/