We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The text was updated successfully, but these errors were encountered:
const obj = {title: 'hello', authors: ['a', 'b', 'c', 'd', function() {}], year: 2011}; JSON.stringify(book); // => {"title":"hello","authors":["a","b","c","d", null],"year":2011} JSON.stringify(book, ['title', 'year']); // => {"title":"hello","year":2011} JSON.stringify(book, function (key, value) { console.log(`key & value: ${key} -> `, value); if (key === 'title') { return undefined; } if (key === 'authors') { return [...value, 2] } return value; }) // 输出的结果为: /* key & value: title -> hello key & value: authors -> [ 'a', 'b', 'c', 'd', [Function] ] key & value: 0 -> a key & value: 1 -> b key & value: 2 -> c key & value: 3 -> d key & value: 4 -> function () {} key & value: 5 -> 2 key & value: year -> 2011 {"authors":["a","b","c","d",null,2],"year":2011} */
如果针对数组返回undefined的,不会删除元素,只会替换为null,函数序列化后也是返回null。
JSON.parse('{"p": 5}', function (k, v) { if(k === '') return v; // 如果到了最顶层,则直接返回属性值, return v * 2; // 否则将属性值变为原来的 2 倍。 }); // { p: 10 }
Sorry, something went wrong.
No branches or pull requests
The text was updated successfully, but these errors were encountered: