【发布时间】:2021-09-09 05:52:00
【问题描述】:
我需要将这个 JSON 展平,使其没有巢,只有贝类,然后是它的名称等。提前致谢!我尝试了一些东西,所以也许可以减少或映射,但我对那些解决问题的知识还不够了解,你们可以分享任何专门针对此类问题的在线资源吗?我经常使用这些,掌握起来会非常方便!
"data": [
{
"name": "Batch1",
"description": "seed",
"age": 2,
"quantity": 1000,
"source": "Hatchery",
"hatchery": "robs hatchery",
"location": "dingle",
"shellfish": {
"name": "oyster"
},
"grade_list": {
"name": "Grade0"
},
"stock_type": {
"name": "seeds"
}
},
{
"name": "Batch2",
"description": "Batch2",
"age": 20,
"quantity": 15700,
"source": "aka",
"hatchery": "aka",
"location": "dingle",
"shellfish": {
"name": "oyster"
},
"grade_list": {
"name": "Grade1"
},
"stock_type": {
"name": "mature"
}
},
{
"name": "5555",
"description": "45",
"age": 1,
"quantity": 134,
"source": "fhh",
"hatchery": "hfhj",
"location": "garden",
"shellfish": {
"name": "oyster"
},
"grade_list": {
"name": "Grade0"
},
"stock_type": {
"name": "seeds"
}
}
]
编辑:我需要这个没有巢,看起来像这样:
"data": [
{
"name": "Batch1",
"description": "seed",
"age": 2,
"quantity": 1000,
"source": "Hatchery",
"hatchery": "robs hatchery",
"location": "dingle",
"shellfish": {
"name": "oyster"
},
"grade_list": {
"name": "Grade0"
},
"stock_type": {
"name": "seeds"
}
},
{
"name": "Batch2",
"description": "Batch2",
"age": 20,
"quantity": 15700,
"source": "aka",
"hatchery": "aka",
"location": "dingle",
"shellfish": {
"name": "oyster"
},
"grade_list": {
"name": "Grade1"
},
"stock_type": {
"name": "mature"
}
},
{
"name": "5555",
"description": "45",
"age": 1,
"quantity": 134,
"source": "fhh",
"hatchery": "hfhj",
"location": "garden",
"shellfish": "oyster",
"grade_list": "Grade0",
"stock_type": "seeds"
}
]
【问题讨论】:
-
这是无效的 JSON。 JSON 不能以
"data":开头。可能缺少一些大括号。此外,如果您在 JavaScript 中有这种数据结构,请不要将其标记为json(阅读使用说明)。 -
“提前致谢”:等等……有什么问题?您可以编辑您的问题并添加您的尝试以及您遇到的问题吗?
-
预期输出是什么?您的描述模棱两可:“我需要将这个 JSON 展平,使其没有巢,只有贝类,然后是它的名称等。”
-
大家好,对不起,我现在要编辑 qs!
-
抱歉现在发了2次模棱两可,没有答案不得不重新发布qs
标签: javascript json