【发布时间】:2019-03-21 09:55:47
【问题描述】:
我想将我的 json 字符串化,但我想排除空的嵌套对象数组。
我的 json 看起来像这样:
{
"Fe": {
"Fh": {
"a" : 1,
"b" : "foo"
},
"Fb": {
"Dbs": [
{
"Nl": "1",
"Dt": "red",
}
],
"Dr": [
{
}
]
}
}
我想忽略“博士”,因为它是空的。
我怎样才能在打字稿/Javascript 中做到这一点?
这里是我尝试过的代码:
const str = JSON.stringify(this.json, replacer);
replacer(key, value) {
if (value === null || value === {})
return undefined;
else
return value;
};
谢谢
【问题讨论】:
-
确保将代码发布在您试图实现目标的地方。
-
是的,请发布您的代码....也看看here
标签: javascript json angular typescript