2016-11-27 56 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