数组格式错误

时间:2016-11-27 13:41:29

标签: angularjs arrays json

我有一个数组如下

{ “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字符串化。

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”: “时间”}]}

1 个答案:

答案 0 :(得分:1)

你可以这么做,

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

<强> DEMO