我应该取消对此类对象的json数组进行解析
{
"httpAlertId": 14,
"httpAlertName": "raja67",
"httpUrl": "http://example.com",
"httpRequestType": "GET",
"httpHeaders": "sadasdsad",
"httpVarMap": "{\"Sdsd\":\"dss\"}",
"httpTimeout": 99,
"httpRetries": 1,
"httpCredentials": "{\"username\":\"somename\",\"password\":\"something\"}",
"mappedAlertActionConfigId": 0
}
我期望的是httpCrenentials
的值必须成为普通的JSON。
答案 0 :(得分:0)
var a = {
"httpAlertId": 14,
"httpAlertName": "raja67",
"httpUrl": "http://example.com",
"httpRequestType": "GET",
"httpHeaders": "sadasdsad",
"httpVarMap": "{\"Sdsd\":\"dss\"}",
"httpTimeout": 99,
"httpRetries": 1,
"httpCredentials": "{\"username\":\"somename\",\"password\":\"something\"}",
"mappedAlertActionConfigId": 0
}
var nJSON = {};
for(key in a){
var val;
try{
nJSON[key] = JSON.parse(a[key]);
}catch(e){
nJSON[key] = a[key];
}
}
console.log(nJSON);