反向JSON.stringify? [英] Reverse of JSON.stringify?

查看:131
本文介绍了反向JSON.stringify?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为像 {'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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆