-3
我有一個JSON作爲下合併兩個JSON在Javascript或JQuery的
"chart": {
"xAxisname": "Months",
"yAxisName": "Year"
}
第二的Json我從的WebAPI接收作爲下
[
{
"productName": "Personal Loan",
"loanAmount": [
{
"amount": 121000
},
{
"amount": 145000
}
]
},
{
"productName": "Car Loan",
"loanAmount": [
{
"amount": 180000
},
{
"amount": 210000
}
]
}
]
我要尋找的輸出
{
"chart": {
"xAxisname": "Months",
"yAxisName": "Year"
},
"dataset": [
{
"productName": "Personal Loan",
"loanAmount": [
{
"amount": "121000"
},
{
"amount": "145000"
}
]
},
{
"productName": "Car Loan",
"loanAmount": [
{
"amount": "180000"
},
{
"amount": "210000"
}
]
}
]
}
我試過$ .extend作爲根據
var obj1 = {
"xAxisname": "Months",
"yAxisName": "Year"
};
var obj2 = [
{
"productName": "Personal Loan",
"loanAmount": [
{
"amount": 121000
},
{
"amount": 145000
}
]
},
{
"productName": "Car Loan",
"loanAmount": [
{
"amount": 180000
},
{
"amount": 210000
}
]
}
];
var finalObj = $.extend(obj1, obj2);
儘管它正在合併,但並不像預期的那樣。
請幫
'VAR finalobj = { '圖':OBJ1, '數據集':OBJ 2}'? –