«

JSON的两种核心方法

yang 发布于 阅读:378 H5阶段


<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            // JSON JavaScript Object Notaion,是一种前后端交互时约定的数据格式
            let obj = { name: "凡凡", age: 30, height: "188" };
            console.log("原对象>>>", obj);

            // 1.JSON.stringify(obj) 将对象转换为对象字符串
            let objStr = JSON.stringify(obj);
            console.log(objStr); // '{ name: "凡凡", age: 30, height: "188" }',对象字符串,伪对象

            // 2.JSON.parse(objStr) 将对象字符串转换为对象
            console.log(JSON.parse(objStr)); // { name: "凡凡", age: 30, height: "188" } 真对象
        </script>
    </body>
</html>

JSON的两种核心方法

版权所有:微4e
文章标题:JSON的两种核心方法
除非注明,文章均为 微4e 原创,请勿用于任何商业用途,禁止转载

推荐阅读:


扫描二维码,在手机上阅读
请先 登录 再评论