12345678910111213141516171819202122232425262728 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <script>
- // JSON 字符串 它里面一般都是对象格式的
- // let jsonStr = '{"name":"张三","age":18}';
- // 把JSON字符串转换为对象 JSON.parse()
- // console.log(jsonStr)
- // let obj = JSON.parse(jsonStr);
- // console.log(obj);
- let obj = {
- name:"张三",
- age:18,
- sex:"男"
- }
- // 把对象转换为JSON字符串 JSON.stringify()
- let jsonStr = JSON.stringify(obj);
- console.log(jsonStr);
- </script>
- </body>
- </html>
|