JavaScript
JavaScript JSON.parse()
返回给定 JSON 字符串转换后的对象。
源代码:
点击运行 »
<h2>从 JSON 字符串中创建一个对象</h2> <p id="demo"></p> <script> var text = '{"employees":[' + '{"name":"蜜蜂教程","site":"https://www.mifengjc.com" },' + '{"name":"Google","site":"http://www.Google.com" },' + '{"name":"Taobao","site":"http://www.taobao.com" }]}'; obj = JSON.parse(text); document.getElementById("demo").innerHTML = obj.employees[1].name + " " + obj.employees[1].site; </script>
运行结果:
点击运行 »