JSON對象如下所示。我想刪除NULL值的所有鍵。另外,如果刪除對之後,如果條目是空白的,那麼也應該刪除。我試圖尋找執行所需任務的腳本,但是我沒有成功。請記住,它是一個NULL字符串,而不是一個對象。我需要實現這個是sails.js,所以Javascript是最受歡迎的語言。如何從使用Javascript的sails.js中的JSON對象中刪除「NULL」字符串?
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? – Marty 2015-02-11 05:00:52
它是更大項目的一部分。但是現在我需要刪除NULL字符串,並且我被卡住了。 – 2015-02-11 05:09:50
你可以改變任何生成的JSON嗎?因爲這將是一個更好的主意。 – Marty 2015-02-11 05:12:11