1
<h2>从 JSON 字符串中创建对象</h2>
2
<p>
3
网站名: <span id="name"></span><br> 网站地址: <span id="url"></span><br>
4
</p>
5
<script>
6
var txt = '{ "sites" : [' +
7
'{ "name":"蜜蜂教程" , "url":"www.mifengjc.com" },' +
8
'{ "name":"google" , "url":"www.google.com" },' +
9
'{ "name":"微博" , "url":"www.weibo.com" } ]}';
10
var obj = eval("(" + txt + ")");
11
document.getElementById("name").innerHTML = obj.sites[0].name
12
document.getElementById("url").innerHTML = obj.sites[0].url
13
</script>