我有这样的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