24_JSON.html 738 B

12345678910111213141516171819202122232425262728
  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. <script>
  10. // JSON 字符串 它里面一般都是对象格式的
  11. // let jsonStr = '{"name":"张三","age":18}';
  12. // 把JSON字符串转换为对象 JSON.parse()
  13. // console.log(jsonStr)
  14. // let obj = JSON.parse(jsonStr);
  15. // console.log(obj);
  16. let obj = {
  17. name:"张三",
  18. age:18,
  19. sex:"男"
  20. }
  21. // 把对象转换为JSON字符串 JSON.stringify()
  22. let jsonStr = JSON.stringify(obj);
  23. console.log(jsonStr);
  24. </script>
  25. </body>
  26. </html>