我有一個名爲data的嵌套javascript對象。有沒有什麼方法可以遍歷它並找到所有具有未定義值的屬性,並將其設置爲字符串「undefined」insted。如果在IE7中屬性值未定義,JSON不會驗證。由於找到並更改undefined值的屬性
{
"Target": "System",
"Systemoperation": "Buy-In",
"Systemorigin": "ABB",
"Subscriptionmode": "Maintain & Evolve",
"Evolveto": "800xA",
"Quoteselection": "Full Quote",
"Commitmenttimeframe": "3 years",
"codevalues": {
"Target": 100,
"Systemoperation": 110,
"Systemorigin": false,
"Subscriptionmode": 4,
"Evolveto": undefined,
"Quoteselection": "fullquote",
"Commitmenttimeframe": 3
},
"Route": [
"System",
"Buy-In",
"ABB",
"Maintain & Evolve",
"800xA",
"Full Quote",
"3 years"
],
"currentsystem": ""
}
這裏是evolteto在codevalues不確定。哪些不驗證(嘗試http://jsonlint.com/)。
任何代碼到目前爲止打電話了嗎? – Niels
請爲我們創建一個示例來看看:http://jsfiddle.net/ – Rumplin
@Niels更新後 – Johan