1.json转js对象:
<script>
var obj = JSON.parse('{ "name":"runoob", "alexa":10000, "site":"www.runoob.com" }');
document.getElementById("demo").innerHTML = obj.name + ":" + obj.site;
</script>
(http://www.runoob.com/json/json-parse.html)
2.js对象转json
var obj = { "name":"runoob", "alexa":10000, "site":"www.runoob.com"};
var myJSON = JSON.stringify(obj);
那么myJson={"name":"runoob","alexa":10000,"site":"www.runoob.com"};
注意:上面obj和myJson是不同的,json里面的key和value都有""来包含,而js对象里面的key可以不用,value如果为字符串也必须用""来包含