我有一个不方便的数据输出,如下所示:
[
{
"object_a": {
"1": "some value of 1",
"2": "some value of 2",
"3": ""
},
"obejct_b": {
"1": "",
"2": "",
"3": "some value of 3"
},
..some other objects..
}
{
"object_a": {
"1": "some value of 1",
"2": "",
"3": "some value of 3"
},
"obejct_b": {
"1": "",
"2": "some value of 2",
"3": ""
},
..some other objects..
}
{
"object_a": {
"1": "",
"2": "some value of 2",
"3": ""
},
"obejct_b": {
"3": "some value of 3",
"1": "some value of 1",
"2": ""
},
..some other objects..
}
]
我不知道还要添加什么。它看起来很简单。不幸的是,我不能更改输出格式。问题是有些数据在“object_a”中,有些在“object_b”中。
所需输出如下所示:
[
{
"object": {
"1": "some value of 1",
"2": "some value of 2",
"3": "some value of 3"
}
..some other objects..
}
{
"object": {
"1": "some value of 1",
"2": "some value of 2",
"3": "some value of 3"
},
..some other objects..
}
{
"object": {
"2": "some value of 2",
"3": "some value of 3",
"1": "some value of 1",
},
..some other objects..
}
]
我找不到用jQuery合并/合并两个对象的方法。
谢谢。
1条答案
按热度按时间qnakjoqk1#
必须做出一些假设:
object_a
和obejct_b
[sic]。object_a
和obejct_b
将具有相同的属性集。object_a
中的任何空字符串键,“merged”结果中的值应该是对应的obejct_b
的值。基于这些假设,我将使用以下代码(注意,我保留了
obejct_b
中的拼写错误)。