在一个相当复杂的 JSON 对象中,我试图获取具有父值的键。
{
"provinces": [
{
"short": "ska",
"tiletype": "water",
"provinceOutlinePath": "M255.848,145.321l19.839,0.054l12.677,8.62l6.085,-8.62l-8.62,-29.41l-30.488,13.637l0.507,15.719Z",
"unionParts": [
{
"id": "main",
"unionPartPath": "M255.848,145.321l19.839,0.054l12.677,8.62l6.085,-8.62l-8.62,-29.41l-30.488,13.637l0.507,15.719Z"
},
{
"id": "main",
"unionPartPath": "M255.848,145.321l19.839,0.054l12.677,8.62l6.085,-8.62l-8.62,-29.41l-30.488,13.637l0.507,15.719Z"
}
]
},
{
"short": "nws",
"tiletype": "water",
"provinceOutlinePath": "M140.038,0.667l34.86,68.197l-6.338,27.888l12.677,3.169l70.988,-17.747l100.144,-62.115l1.268,-19.392l-213.599,0Z",
"unionParts": [
{
"id": "main",
"unionPartPath": "M140.038,0.667l34.86,68.197l-6.338,27.888l12.677,3.169l70.988,-17.747l100.144,-62.115l1.268,-19.392l-213.599,0Z"
}
]
}
]
}
我想将对象更改为:
[
{
"short": ska,
"unionPartPath": "<Path>"
},
{
"short": ska,
"unionPartPath": "<AnotherPath>"
},
{
"short": nws,
"unionPartPath": "<Path>"
}
]
我已经浏览了整个文档,并没有发现任何类似.parent()
方法的东西。
也许可以通过一些更高阶的函数来实现预期的结果,但目前我不知道如何实现这一点。