我有一个结构如下的对象:
{
"productName": {
"de-DE": "Hudson",
"en-US": "Hudson Wall Cup",
"fr-FR": "Hudson Wall Cup FR"
},
"productDescription": {
"en-US": "Wall Hanging Glass Flower Vase and Terrarium",
"it-IT": "Wall Hanging Glass Flower Vase and Terrarium IT"
},
"sizetypecolor": {
"en-US": "3 x 3 x 5 inches; 5.3 ounces"
},
"image": {
"en-US": [
{
"sys": {
"type": "Link",
"linkType": "Asset",
"id": "Xc0ny7GWsMEMCeASWO2um"
}
}
],
"it-IT": [
{
"sys": {
"type": "Link",
"linkType": "Asset",
"id": "Xc0ny7GWsMEMCeASWO2um"
}
}
]
},
"tags": {
"en-US": ["vase", "flowers", "accessories", "translation"],
"jp": ["vase", "flowers", "accessories", "translation"]
},
"website": {
"en-US": "http://www.amzon.com/dp/B00E82D7I8/"
}
}
每个项目(productName等productDescription)都包含键值对,其中键是语言代码,值是该语言的相关文本。我想过滤掉所有没有“en-US”键的嵌套键值对,因此返回以下对象:
{
"productName": {
"en-US": "Hudson Wall Cup"
},
"productDescription": {
"en-US": "Wall Hanging Glass Flower Vase and Terrarium"
},
"sizetypecolor": {
"en-US": "3 x 3 x 5 inches; 5.3 ounces"
},
"image": {
"en-US": [
{
"sys": {
"type": "Link",
"linkType": "Asset",
"id": "Xc0ny7GWsMEMCeASWO2um"
}
}
]
},
"tags": {
"en-US": ["vase", "flowers", "accessories", "translation"]
},
"website": {
"en-US": "http://www.amzon.com/dp/B00E82D7I8/"
}
}
过滤掉非嵌套对象有很多有用的答案,但我一直无法找到适用于这种嵌套结构的解决方案。过滤掉不必要的键值对的最佳方法是什么?
犯罪嫌疑人X
相关分类