null
我有一个 JSON obj,经过一些操作(比如删除一些片段)后,我打印它,除了我有一些值之外,一切看起来都很好。我该如何删除这些?
我使用JSON.stringify(obj, null, 2)
方法打印,如下所示:
{
"store": {
"book": [
null,
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
},
null,
{
"category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
],
"bicycle": {
"color": "red",
null,
"price": 19.95
}
}
}
我希望它非常紧凑且非常干净(删除额外的 3 个null
值):
{
"store": {
"book": [
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
},
{
"category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
}
}