首页 > Web开发 > 详细

JSON.parse() 和 JSON.stringify() 的作用和注意点

时间:2021-07-09 00:45:35      阅读:17      评论:0      收藏:0      [点我收藏+]

JSON.parse() 和 JSON.stringify() 的作用和注意点

JSON.stringify()的作用

JSON.stringify是将json对象转换成json字符串的方法

JSON.parse()的作用

JSON.parse() 是将json字符串转换成json对象的方法

注意点 时间类型对象(New Date()) 的转换

    <div @click="jsonparse" style="margin: 20px 0">jsonparse</div>
    <div @click="jsonstringify" style="margin: 20px 0">jsonstringify</div>

 jsonparse() {
      let a = JSON.stringify(new Date());
      console.log(‘JSON.stringify(new Date())‘,a);
      let b = JSON.stringify({name:"123123"});
      console.log("JSON.stringify({name:‘123123‘})",b);
        let d = JSON.parse(b);
      console.log("JSON.parse(b)",d);
      console.log("JSON.parse(b).name",d.name);
        let c= JSON.parse(a);
        console.log("new Date().getFullYear()",new Date().getFullYear());
      console.log("JSON.parse(a)",c);
      console.log("typeof c",typeof c);
        console.log("c.getFullYear()",c.getFullYear());
    },
    jsonstringify() {
      let a = {
          name: ‘123‘,
        },
        b = new Date()
      let c = JSON.stringify(a)
      let d = JSON.stringify(b)
      console.log("JSON.stringify(a)",c)
      console.log("JSON.stringify(b)",Fd)
    },

技术分享图片

JSON.parse() 和 JSON.stringify() 的作用和注意点

原文:https://www.cnblogs.com/panghu123/p/14987895.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!