JSON.stringify 替换 属性
作者:
醋留香 | 来源:发表于
2022-08-10 16:22 被阅读0次function replacer(key, value) {
if (typeof value === "string") {
return undefined;
}
return value;
}
var foo = {foundation: "Mozilla", model: "box", week: 45, transport: "car", month: 7};
var jsonString = JSON.stringify(foo, replacer);
JSON 序列化结果为 {"week":45,"month":7}.
如果是一个数组:
JSON.stringify(foo, ['week', 'month']);
// '{"week":45,"month":7}', 只保留 “week” 和 “month” 属性值。
本文标题:JSON.stringify 替换 属性
本文链接:https://www.haomeiwen.com/subject/ihjawrtx.html
网友评论