首页 > 代码库 > JSON.parse
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。