【发布时间】:2019-03-25 13:24:28
【问题描述】:
我有这个 JSON,我正在使用 NodeJS 解析它,它需要重组为我在下面添加的第二个 JSON。
在第一个 JSON 中,rows 对象有两个 pages 对象(可以存在任意数量的 pages 对象),它们包含所有相同的键和值,但 values 和 display 除外键。
{
"pages": [
{
"label": "SomeLabel",
"name": "Some",
"sections": [
{
"type": "Repeat",
"label": "Label 1",
"name": "Name 1",
"rows": [
{
"pages": [
{
"label": "Label 1",
"name": "Name 1",
"sections": [
{
"type": "Flow",
"label": "Label 2",
"name": "Name 2",
"answers": [
{
"label": "Question Label",
"question": "Question",
"values": [
"Value A"
],
"valuesMetadata": [
{
"display": "Display A",
"row": {
"columns": []
}
}
]
}
]
}
]
}
]
},
{
"pages": [
{
"label": "Label 1",
"name": "Name 1",
"sections": [
{
"type": "Flow",
"label": "Label 2",
"name": "Name 2",
"answers": [
{
"label": "Question Label",
"question": "Question",
"values": [
"Value B"
],
"valuesMetadata": [
{
"display": "Display B",
"row": {
"columns": []
}
}
]
}
]
}
]
}
]
}
],
"footer": null
}
]
}
]
}
在第二个 JSON 中,rows 对象有一个 pages 对象,其中 values 和 display 键有多个值(非公共值)。
{
"pages": [
{
"label": "SomeLabel",
"name": "Some",
"sections": [
{
"type": "Repeat",
"label": "Label 1",
"name": "Name 1",
"rows": [
{
"pages": [
{
"label": "Label 1",
"name": "Name 1",
"sections": [
{
"type": "Flow",
"label": "Label 2",
"name": "Name 2",
"answers": [
{
"label": "Question Label",
"question": "Question",
"values": [
"Value A",
"Value B"
],
"valuesMetadata": [
{
"display": [
"Display A",
"Display B"
],
"row": {
"columns": []
}
}
]
}
]
}
]
}
]
}
],
"footer": null
}
]
}
]
}
所以,我想知道执行此操作的快速简单的步骤。请告诉我解决这个问题的过程和方法。
谢谢
【问题讨论】:
-
你可以在小例子中更改它
input和output以便他们可以轻松提供帮助 -
如果您明确告诉我们新旧 json 之间的差异,会更容易阅读/解决。
-
嘿@Scorpioo590,我用更短的 JSON 和更具描述性的摘要编辑了我的帖子。请帮帮我!
-
@G.aziz 请查看我编辑的问题并帮助我
标签: javascript arrays json object nested