JSON.parse
Posted BadGirl_Xiao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JSON.parse相关的知识,希望对你有一定的参考价值。
把字符串为JSON格式的数据转换为javascript对象
把javascript对象转换为JSON格式的字符串数据
<head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <div id="demo"></div> <script> var text = ‘{ "sites" : [‘ + ‘{ "name":"Runoob" , "url":"www.runoob.com" },‘ + ‘{ "name":"Google" , "url":"www.google.com" },‘ + ‘{ "name":"Taobao" , "url":"www.taobao.com" } ]}‘; console.log(text); //{ "sites" : [{ "name":"Runoob" , "url":"www.runoob.com" },{ "name":"Google" , "url":"www.google.com" },{ "name":"Taobao" , "url":"www.taobao.com" } ]} obj = JSON.parse(text); console.log(obj); //Object {sites: Array(3)}sites: Array(3)__proto__: Object aa = JSON.stringify(obj); console.log(aa); //{"sites":[{"name":"Runoob","url":"www.runoob.com"},{"name":"Google","url":"www.google.com"},{"name":"Taobao","url":"www.taobao.com"}]} document.getElementById("demo").innerhtml = obj.sites[1].name + " " + obj.sites[1].url; </script> </body> </html>
以上是关于JSON.parse的主要内容,如果未能解决你的问题,请参考以下文章
node json.parse和querystring.parse的区别