我有2个json对象,我想合并。我试过使用concat
和merge
函数,但结果不是我想要的。任何帮助,将不胜感激。结合2个jsons对象
var jason1 =
{
"book1": {
"price": 10,
"weight": 30
},
"book2": {
"price": 40,
"weight": 60
}
};
,这是其他物体
var jason2 =
{
"book3": {
"price": 70,
"weight": 100
},
"book4": {
"price": 110,
"weight": 130
}
};
这就是我想要的东西:
var jasons =
{
"book1": {
"price": 10,
"weight": 30
},
"book2": {
"price": 40,
"weight": 60
}
"book3": {
"price": 70,
"weight": 100
},
"book4": {
"price": 110,
"weight": 130
}
};
那些不是JSON对象,它们只是对象。 JSON是一种将对象表示为字符串的方式(例如,通过网络传输)。 – Barmar
[我怎样才能动态合并两个JavaScript对象的属性?](http://stackoverflow.com/questions/171251/how-can-i-merge-properties-of-two-javascript-objects-dynamically) –