使用 JSON 字符串化
- <!DOCTYPE html>
- <html>
- <body>
- <h1>从 JavaScript 对象创建 JSON 字符串</h1>
- <p id="demo"></p>
- <script>
- var obj = { name: "Bill", age: 62, city: "Seatle" };
- var myJSON = JSON.stringify(obj);
- document.getElementById("demo").innerHTML = myJSON;
- </script>
- </body>
- </html>