2016-11-27 71 views
-3

我有一個數組如下陣列格式錯誤

{ 「contractID」:27112016185818 「contractName」: 「DDF」, 「供應商ID」:5 「supplierName」: 「HH」, 「的productID」:44 , 「產品名稱」: 「GG」, 「計量單位」: 「UU」, 「數量」:6, 「pricePerUOM」:6, 「totalPrice」:36, 「貨幣」: 「INR」, 「supplyByDate」: 「01112016」 「createdDate」: 「27112016」, 「loginuser」: 「買方」, 「chain_id」: 「supplychainintegrity」, 「高度」:244432 「num_txs」:1, 「pendingWith」: 「」, 「block_hash」:「哈希」, 「block_data」: 「數據」, 「data_hash」: 「datahash」, 「block_time」: 「時間」}

我想把它轉換成以下

[{"contractID":27112016185818,"contractName":"ddf","supplierID":5,"supplierName":"hh","productID":44,"productName":"gg","uom":"uu","quantity":6,"pricePerUOM":6,"totalPrice":36,"currency":"inr","supplyByDate":"01112016","createdDate":"27112016","loginuser":"buyer","chain_id":"supplychainintegrity","height":244432,"num_txs":1,"pendingWith":"","block_hash":"hash","block_data":"data","data_hash":"datahash","block_time":"time"}] 

它爲json stringification。

jsonObj["row"]=currentArray; 
newArray=JSON.stringify(jsonObj); 

我newArray如下

{"row":{"contractID":27112016185818,"contractName":"ddf","supplierID":5,"supplierName":"hh","productID":44,"productName":"gg","uom":"uu","quantity":6,"pricePerUOM":6,"totalPrice":36,"currency":"inr","supplyByDate":"01112016","createdDate":"27112016","loginuser":"buyer","chain_id":"supplychainintegrity","height":244432,"num_txs":1,"pendingWith":"","block_hash":"hash","block_data":"data","data_hash":"datahash","block_time":"time"}} 

需要如下

{ 「行」:[{ 「contractID」:27112016185818, 「contractName」: 「DDF」, 「供應商ID」: 5, 「supplierName」: 「HH」, 「的productID」:44, 「產品名稱」: 「GG」, 「計量單位」: 「UU」, 「數量」:6, 「pricePerUOM」:6, 「totalPrice」:36, 「貨幣」: 「INR」, 「supplyByDate」: 「01112016」, 「createdDate」: 「27112016」, 「loginuser」: 「買方」, 「chain_id」: 「supplychainintegrity」, 「高度」:244432, 「num_txs」: 1, 「pendingWith」: 「」, 「block_hash」: 「散列」, 「block_data」: 「數據」, 「data_hash」:」 datahash」, 「block_time」: 「時間」}]}

+0

,這樣的差異是清晰的,請格式化你的JSON。 –

+0

@Tim Biegeleisen我沒有得到你 –

+0

試試[this](http://jsonlint.com/)網站。這是一個強大的工具,用於確定您的JSON是否結構合理,如果不正確,它會告訴您哪裏存在不一致。 – FDavidov

回答

1

你可以簡單的做到這一點,

$scope.newarray = []; 
$scope.myObj = data.row; 
$scope.newarray.push($scope.myObj); 
console.log($scope.newarray); 

DEMO