实例代码“Ctrl+/”提示“F11/ESC”全屏 返回 格式化 恢复 运行
x
 
1
<!DOCTYPE html>
2
<html>
3
<head>
4
    <title>JSON Stringify Example</title>
5
</head>
6
<body>
7
    <p>This example serializes an object and passes in a filter function.</p>
8
    <script type="text/javascript">
9
        var book = {
10
                       "title": "Professional JavaScript",
11
                        "authors": [
12
                            "Nicholas C. Zakas"
13
                        ],
14
                        edition: 3,
15
                        year: 2011,
16
                        toJSON: function(){
17
                            return this.title;
18
                        }
19
                   };
20
21
        var jsonText = JSON.stringify(book);
22
        alert(jsonText);
23
24
    </script>
25
</body>
26
</html>
27