【问题标题】:Array format error数组格式错误
【发布时间】:2016-11-27 13:41:28
【问题描述】:

我有一个数组如下

{"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": "买方","chain_id":"供应链完整性","height":244432,"num_txs":1,"pendingWith":"","block_hash":"hash","block_data":"data","data_hash" :"datahash","block_time":"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"}}

需要如下

{"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_hash":"datahash","block_time":"time"}]}

【问题讨论】:

  • 请格式化您的 JSON,以使差异清晰可见。
  • @Tim Biegeleisen 我没听懂你
  • 试试this 网站。这是一个强大的工具,可以检查您的 JSON 结构是否正确,如果没有,它会告诉您不一致的位置。
  • 我已经检查过验证为真
  • @AdarshMPallickal - 他说你的 JSON 不可读。格式化它。

标签: angularjs arrays json


【解决方案1】:

你可以这样做,

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

DEMO

【讨论】:

    猜你喜欢
    • 2017-06-23
    • 2012-06-04
    • 1970-01-01
    • 1970-01-01
    • 2019-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多