我有这个简单的JSON阵列结构的Javascript:转换JSON阵列级联的JSON
[
[ "1000", "Kangar","Perlis" ],
[ "1532", "Kangar", "Perlis" ],
[ "2000", "Kuala Perlis", "Perlis" ],
[ "6250", "Alor Setar", "Kedah" ],
[ "6300", "Kuala Nerang", "Kedah" ]
]
现在我想结构JSON这样
{
"Perlis":
{
"Kangar": [ "1000", "1532" ],
"Kuala Perlis": [ "2000" ]
},
"Kedah":
{
"Alor Setar":["6250"],
"Kuala Nerang":["2000"]
}
}
因此,如何能利用我达到这个效果JavaScript的目的?
你尝试过这么远吗? – Zim84
您可以使用'JSON.stringify'的[space参数](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_space_argument) – hindmost