arrays - 合并两个不同的json对象
问题描述
我有一个场景,我将两个 json 对象组合在一个表中,它们在表中存储为两个不同的行。
考虑到以下几点,形成了组合的 json 对象
如果标签存在于第二行,则考虑该标签的值,如果不存在,则考虑第一行的值。
仅考虑第一行中存在的标签。JSON数据如下:
第 1 行 JSON ----------
[
{
"key": "service",
"type": "radio",
"templateOptions": {
"label": "Service",
"options": [
{
"value": "noService",
"label": "Do Nothing",
"color": "green"
},
{
"value": "spin",
"label": "Spin Cutter",
"color": "yellow"
},
{
"value": "replace",
"label": "Replace Cutter",
"color": "red"
}
]
}
},
{
"key": "wear",
"type": "radio",
"templateOptions": {
"label": "Wear",
"options": [
{
"value": "w1",
"label": "Wear 1",
"color": "orange"
},
{
"value": "w2",
"label": "Wear 2",
"color": "#123456"
},
{
"value": "w3",
"label": "Wear 3",
"color": "#BBBB00"
}
]
}
}
]
第 2 行 JSON ----------
[
{
"key": "service",
"templateOptions": {
"label": "서비스",
"options": [
{
"value": "noService",
"label": "아무것도하지 마세요",
"color": "#330000"
},
{
"value": "spin",
"label": "스핀 커터",
"color": "#AA0000"
},
{
"value": "replace",
"label": "커터 교체",
"color": "#FF0000"
}
]
}
},
{
"key": "wear",
"templateOptions": {
"label": "입고 있다",
"options": [
{
"value": "w2",
"color": "#770000"
},
{
"value": "w3",
"label": "착용 3",
"color": "#990000"
},
{
"value": "w123",
"label": "커도하`, color: ‘#440000"
}
]
}
}
]
组合 JSON ----------
[
{
"key": "service",
"type": "radio",
"templateOptions": {
"label": "서비스",
"options": [
{
"value": "noService",
"label": "아무것도하지 마세요",
"color": "#330000"
},
{
"value": "spin",
"label": "스핀 커터",
"color": "#AA0000"
},
{
"value": "replace",
"label": "커터 교체",
"color": "#FF0000"
}
]
}
},
{
"key": "wear",
"type": "radio",
"templateOptions": {
"label": "입고 있다",
"options": [
{
"value": "w1",
"label": "Wear 1",
"color": "orange"
},
{
"value": "w2",
"label": "Wear 2",
"color": "#770000"
},
{
"value": "w3",
"label": "착용 3",
"color": "#990000"
}
]
}
}
]
解决方案
推荐阅读
- flutter - 状态改变时 Flutter OpenContainer 重建?
- c - 我从 CS50x 中提出了我自己版本的“现金”问题,我可以优化它吗?
- python - SyntaxError:with 语句套件中的语法无效
- python-3.x - 指出 Python 列表中方向的变化
- python - 继续从类中的列表中的项目中获取 ID
- youtube - 调用活动:列表在使用参数“mine=true”时失败(Youtube Data API V3)
- c# - C#:无参数方法和值变量
- ofbiz - 更改现有组件/应用程序?
- javascript - 如果条形高度等于端口高度,图表 js 图例将被切断 - 图表 js
- python - 关闭 Tkinter 窗口时出现图像问题