6.json.html 879 B

123456789101112131415161718192021222324252627282930313233
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <!-- json 数据格式
  10. 键名必须是双引号
  11. 只能是双引 不能是单引号
  12. 不能注释
  13. 最后一个属性后面不能加逗号
  14. json是字符串
  15. JSON.stringify(js对象转json对象)
  16. JSON.parse(json对象转js对象)
  17. -->
  18. <script>
  19. let obj1 = {
  20. name:'你好'
  21. }
  22. let obj2 = {
  23. "name":"家家"
  24. }
  25. // console.log(JSON.parse(JSON.stringify(obj1)));
  26. let obj3 = JSON.stringify(obj1);
  27. console.log(obj3)
  28. obj3 = {"name":"你好"};
  29. // console.log(obj1,'obj1');
  30. console.log((obj3),'obj3');
  31. </script>
  32. </body>
  33. </html>