一,效果图。

【代码笔记】Web-JavaScript-JavaScript JSON_json

二,代码。

【代码笔记】Web-JavaScript-JavaScript JSON_json_02
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>JavaScript JSON</title>
</head>

<body>
    <h2>为JSON字符串创建对象</h2>
    <p id="demo"></p>
    <script>
    var text = '{"employees":[' +
        '{"firstName":"John","lastName":"Doe" },' +
        '{"firstName":"Anna","lastName":"Smith" },' +
        '{"firstName":"Peter","lastName":"Jones" }]}';

    obj = JSON.parse(text);
    document.getElementById("demo").innerHTML = obj.employees[1].firstName + " " + obj.employees[1].lastName;
    </script>
</body>

</html>
【代码笔记】Web-JavaScript-JavaScript JSON_json_02

 

参考资料:《菜鸟教程》