添加里面的Json新對象,我有一個JSON對象,像這種在前面
[{"SubLoc":"a","Description":"A","Equipment":""},{"SubLoc":"b","Description":"B","Equipment":""},{"SubLoc":"c","Description":"C","Equipment":""},{"SubLoc":"d","Description":"D","Equipment":""}]
我要在前面加一個多個屬性,使得JSON看起來像
[{"SubLoc":"Select","Description":"Select","Equipment":""},{"SubLoc":"a","Description":"A","Equipment":""},{"SubLoc":"b","Description":"B","Equipment":""},{"SubLoc":"c","Description":"C","Equipment":""},{"SubLoc":"d","Description":"D","Equipment":""}]
我試着不印字像這個 -
$scope.JsonVar.unshift({SubLoc:'Select', Description:'Select'});
但它給我造成這樣的...
[{"SubLoc":"Select","Description":"Select","Equipment":""}[{"SubLoc":"a","Description":"A","Equipment":""},{"SubLoc":"b","Description":"B","Equipment":""},{"SubLoc":"c","Description":"C","Equipment":""},{"SubLoc":"d","Description":"D","Equipment":""}]]
你的結果甚至不是有效的JSON,並且在調用'unshift'時有一個表面的'.'。請確保你解決了你的問題中的所有錯別字! – muenchdo