标签:efi turn 使用 class log pac return bsp 负数
在使用JSON.stringify()对JSON数据进行序列化时
1> 如果里面的属性是function,则会被忽略
const data = { a: ‘a‘, fn: funciton() { return true } } JSON.stringify(data); // "{"a":"a"}" *******fn属性被忽略了**********
2> 如果里面的属性的值是undefined, 也是会被忽略的
const data = { a: ‘a‘, b: undefined } JSON.stringify(data); // "{"a":"a"}" *******b属性被忽略了**********
3>但是如果里面的属性值是null, 是不会被忽略的
const data = { a: ‘a‘, b: null } JSON.stringify(data); // "{"a":"a","b":null}" *******b属性没有被忽略**********
其实JSON.stringify()有三个参数:stringify(value, [replacer, space](可选的, replacer: 自定义的函数,space: 格式化输出(相当于tab键,值的范围是[1(负数的时候默认是1),10]))),为了属性值为function和undefined的属性在序列化的时候不要被忽略,我们可以对replacer做操作
比如:
标签:efi turn 使用 class log pac return bsp 负数
原文地址:http://www.cnblogs.com/yyh1/p/7246490.html