【发布时间】:2015-04-11 09:12:37
【问题描述】:
JSON 对象如下图所示。我想删除所有值为 NULL 的键。此外,如果在删除该对后,如果条目为空白,则也应删除该条目。我曾尝试寻找执行所需任务的脚本,但我没有成功。请记住,它是一个 NULL 字符串,而不是一个对象。我需要实现的是sails.js,所以Javascript是最首选的语言。
var JSONobj ={ "regex_attributes": {
"matching attributes": {
"transaction_amount": {
"matching_position": "1"
},
"total_amount_due": {
"matching_position": "NULL"
},
"transaction_date": {
"matching_position": "NULL",
"date_format": "NULL"
},
"current_credit": {
"matching_position": "NULL"
},
"available_credit": {
"matching_position": "NULL"
},
"date_posted": {
"matching_position": "NULL",
"date_format": "NULL"
},
"merchant": {
"matching_position": "NULL"
},
"bill_date": {
"matching_position": "NULL",
"date_format": "NULL"
},
"bill_due_date": {
"matching_position": "NULL",
"date_format": "NULL"
},
"bill_amount": {
"matching_position": "NULL"
},
"account_number_ending": {
"matching_position": "2"
},
"balance_date": {
"matching_position": "NULL",
"date_format": "NULL"
},
"available_balance": {
"matching_position": "NULL"
}
},
"additional_processing": [ //Array
{
"sms_sender_name": "NULL",
"type_of_account_to_find": "NULL",
"attribute": "description",
"operation": "pre_add",
"pre_add_1": "Credit"
}
],
"account_details": {
"credit_or_debit": "CREDIT",
"type_of_transaction": "INT",
"type_of_account": "SAVINGS",
"type_of_action": "TRANSACTION",
"bills_account_type": "NULL"
}
} }
【问题讨论】:
-
你从哪里得到这个 JSON?
-
这是一个更大项目的一部分。但现在我需要删除 NULL 字符串,我被困在了那里。
-
你能改变任何生成 JSON 的东西吗?因为那会是一个更好的主意。
-
好的,我会试试这个,而不是这个。但是,如果您有解决方案,请告诉我。谢谢。
-
最好尽可能在上游尝试解决问题 :-)
标签: javascript json sails.js