我有這樣的JSON數據data:[ {'country':'uk','district':'whitefield','ward':'eastward','county':'eastcounty1','company':'privatecompany'}, {'country':'uk','district':'whitefield','ward':'eastward','county':'eastcounty1','company':'privatecompany2'}, {'country':'uk','district':'whitefield','ward':'eastward','county':'eastcounty2','company':'privatecompany3'}, {'country':'uk','district':'whitefield','ward':'westward','county':'westcounty1','company':'privatecompany'}, {'country':'uk','district':'blackfield','ward':'westward','county':'eastcounty1','company':'privatecompany'}, {'country':'india','district':'andhra','ward':'ramnagar','county':'','company':'privatecompany'} ]
JSON格式分層數據
我不得不將其轉換爲階層結構如..
data:{'uk':{
"whitefield":{
"eastward":{
"eastcounty1":["privateCompany","privateCompany2"],
"eastcounty2":["privatecompany3"]
},
"westward":{
"westcounty1":["privatecompany"],
"eastcounty1":["privatecompany"]
}
},
"blackfield":{
"westward":{"eastcounty1":["privatecompany"]}
}
},
"india":{
"andhra":{
"ramnagar":["privatecompany"]
}
}}
在上述情況下
我有縣=」「或在一個場景中,縣= null,因此它被替換爲如上所示在ramnagar病房。
你嘗試過什麼到目前爲止?我們願意幫助您,但我並沒有在這裏看到與* code *有關的問題。 – Jordy 2015-04-01 11:53:01
是的,我已經嘗試了很多方式使用for循環和所有,但我正在尋找一個適度和最好的方法來解決這個問題,希望你能理解 – 2015-04-02 17:19:51