JSON.stringify 的反转? [英] Reverse of JSON.stringify?
本文介绍了JSON.stringify 的反转?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在字符串化一个对象,例如 {'foo': 'bar'}
I'm stringyfing an object like {'foo': 'bar'}
如何将字符串变回对象?
How can I turn the string back to an object?
推荐答案
您需要 JSON.parse()
字符串.
You need to JSON.parse()
the string.
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);
}
这篇关于JSON.stringify 的反转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文