2013-03-05 84 views
1

我有一個JSON像下面過濾一個JSON

{ 
    "status": { 
     "On Hold": true, 
     "Completed": true, 
     "Work In Progress": false, 
     "Closed": false, 
     "Initiation": false 
    }, 
    "application": { 
     "Athena":false, 
     "EWindow":false, 
     "EWS":true, 
     "FACT":false, 
     "FTP":false, 
     "Hardware":false, 
     "Harmony":true, 
     "Hermes":false 
    } 
} 

我要過濾這個JSON包含它的價值就爲真像下面

{"status":"On Hold,Completed","application":"EWS,Harmony"} 

任何幫助深表感謝

項目
+0

請注意,您需要從javascript或java過濾,也讓我們知道您從Web服務或NoSQL DB檢索的json,如couchDB,Mango DB等? – Fahad 2013-03-05 11:18:03

+0

@karaxuna答案很安靜! – Garfield 2013-03-05 11:37:22

+0

爲什麼用angularjs標記?你想要AngularJS過濾器還是...? – Stewie 2013-03-05 11:44:47

回答

1
var data = {"status":{"On Hold":true,"Completed":true,"Work In Progress":false,"Closed":false,"Initiation":false},"application":{"Athena":false,"EWindow":false,"EWS":true,"FACT":false,"FTP":false,"Hardware":false,"Harmony":true,"Hermes":false}} 

var newData = {}; 
for(var prop in data){ 
    var subData = data[prop]; 
    var xs = []; 
    for(var subProp in subData){ 
     if(subData[subProp] === true) 
       xs.push(subProp); 
    } 
    newData[prop] = xs.join(','); 
} 
+0

Thanks。這工作。 – Saravanan 2013-03-05 12:05:03

+0

@ user548846歡迎您:) – karaxuna 2013-03-05 12:05:40