-3
我給出JSON對象如下:JSON對象處理
resultTable = [
{
id: "005470021180",
balance: "0.00",
accountName: "Money Master",
category: "Banking",
currency: "CAD",
entitlements: [
]
},
{
id: "005470021288",
balance: "0.00",
accountName: "Money Master",
category: "Banking",
currency: "CAD"
},
{
id: "005470044628",
balance: "-72,116.01",
accountName: "Money Master",
category: "Banking",
currency: "CAD"
},
{
id: "40592000495201",
accountName: "Business Loan",
category: "Borrowing",
cad_balance: "0.00"
},
{
id: "40592000495202",
accountName: "Business Loan",
category: "Borrowing",
cad_balance: "0.00"
},
{
id: "40592000495203",
accountName: "Business Loan",
category: "Investing",
cad_balance: "0.00"
},
{
id: "40592000495204",
accountName: "Business Loan",
category: "INVESTING",
cad_balance: "0.00"
},
{
usd_balance: "1,080.27",
id: "55300070",
accountName: "Scotia iTRADE",
category: "INVESTING",
cad_balance: "272,166.59"
}
];
我需要在JS的輸出爲:
resulttable = [
{
"Banking": {
id: "005470021180",
balance: "0.00",
accountName: "Money Master",
category: "Banking",
currency: "CAD",
entitlements: [
]
},
{
id: "005470021288",
balance: "0.00",
accountName: "Money Master",
category: "Banking",
currency: "CAD"
},
{
id: "005470044628",
balance: "-72,116.01",
accountName: "Money Master",
category: "Banking",
currency: "CAD"
}
},
{
"Borrowing": {
id: "40592000495201",
accountName: "Business Loan",
category: "Borrowing",
cad_balance: "0.00"
},
{
id: "40592000495202",
accountName: "Business Loan",
category: "Borrowing",
cad_balance: "0.00"
}
},
{
""INVESTING":{
{
id : "40592000495203",
accountName : "BusinessLoan",
category : "Investing",
cad_balance : "0.00"
},
{
id : "40592000495204",
accountName : "BusinessLoan",
category : "INVESTING",
cad_balance : "0.00"
},
{
usd_balance : "1,080.27",
id : "55300070",
accountName : "ScotiaiTRADE",
category : "INVESTING",
cad_balance : "272,166.59"
}} ];
你有什麼試過?你能否正確地格式化你的問題中的代碼? – Blender
看起來他想對數組進行排序.. – user1600124
不,他希望對項目進行分類 – epoch