阅读 117

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

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

JSON.stringify()的作用

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

JSON.parse()的作用

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

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

    
jsonparse
jsonstringify
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) },

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

文章分类
代码人生
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐