Jsondata以大块的形式返回并附加/附加

时间:2016-08-16 16:33:49

标签: sql-server node.js express sql-server-2016-express

如何在没有数据的情况下一次性获取数据?

[
  [
    {
      "JSON_F52E2B61-18A1-11d1-B105-00805F49916B": "[{\"OffersCount\":4,\"Id\":1,\"Name\":\"@M The World Cuisine Restaurant Cocoon.\",\"Code\":\"MCC\",\"Status\":\"1\",\"Offers\":{\"Id\":1,\"Name\":\"50% Off on Wine\"}},{\"OffersCount\":4,\"Id\":1,\"Name\":\"@M The World Cuisine Restaurant Cocoon.\",\"Code\":\"MCC\",\"Status\":\"1\",\"Offers\":{\"Id\":2,\"Name\":\"30% Off on IMFL\"}},{\"OffersCount\":4,\"Id\":1,\"Name\":\"@M The World Cuisine Restaurant Cocoon.\",\"Code\":\"MCC\",\"Status\":\"1\",\"Offers\":{\"Id\":82,\"Name\":\"Gift Vouchers\"}},{\"OffersCount\":4,\"Id\":2,\"Name\":\"Alfresco - Four Points By Sheraton Pune\",\"Code\":\"AFS\",\"Status\":\"1\",\"Offers\":{\"Id\":3,\"Name\":\"10% Off on Food & Soft Beverages\"}},{\"OffersCount\":4,\"Id\":3,\"Name\":\"April Rain\",\"Code\":\"APR\",\"Status\":\"1\",\"Offers\":{\"Id\":4,\"Name\":\"10% Off on Lunch Buffet\"}}]"
    }
  ],
  [
    {
      "JSON_F52E2B61-18A1-11d1-B105-00805F49916B": "[{\"OffersCount\":4,\"Id\":1,\"Name\":\"@M The World Cuisine Restaurant Cocoon.\",\"Code\":\"MCC\",\"Status\":\"1\",\"Offers\":{\"Id\":1,\"Name\":\"50% Off on Wine\"}},{\"OffersCount\":4,\"Id\":1,\"Name\":\"@M The World Cuisine Restaurant Cocoon.\",\"Code\":\"MCC\",\"Status\":\"1\",\"Offers\":{\"Id\":2,\"Name\":\"30% Off on IMFL\"}},{\"OffersCount\":4,\"Id\":1,\"Name\":\"@M The World Cuisine Restaurant Cocoon.\",\"Code\":\"MCC\",\"Status\":\"1\",\"Offers\":{\"Id\":82,\"Name\":\"Gift Vouchers\"}},{\"OffersCount\":4,\"Id\":2,\"Name\":\"Alfresco - Four Points By Sheraton Pune\",\"Code\":\"AFS\",\"Status\":\"1\",\"Offers\":{\"Id\":3,\"Name\":\"10% Off on Food & Soft Beverages\"}},{\"OffersCount\":4,\"Id\":3,\"Name\":\"April Rain\",\"Code\":\"APR\",\"Status\":\"1\",\"Offers\":{\"Id\":4,\"Name\":\"10% Off on Lunch Buffet\"}}]"
    }
  ]
]

1 个答案:

答案 0 :(得分:0)

Sql Server可能会对这些值进行转义,以便将它们安全地保存为字符串。如果JSON解析器无法取消它们,您可能必须自己逃避它们:

var result = [
    [
      {
      "JSON_F52E2B61-18A1-11d1-B105-00805F49916B": "[{\"OffersCount\":4,\"Id\":1,\"Name\":\"@M The World Cuisine Restaurant Cocoon.\",\"Code\":\"MCC\",\"Status\":\"1\",\"Offers\":{\"Id\":1,\"Name\":\"50% Off on Wine\"}},{\"OffersCount\":4,\"Id\":1,\"Name\":\"@M The World Cuisine Restaurant Cocoon.\",\"Code\":\"MCC\",\"Status\":\"1\",\"Offers\":{\"Id\":2,\"Name\":\"30% Off on IMFL\"}},{\"OffersCount\":4,\"Id\":1,\"Name\":\"@M The World Cuisine Restaurant Cocoon.\",\"Code\":\"MCC\",\"Status\":\"1\",\"Offers\":{\"Id\":82,\"Name\":\"Gift Vouchers\"}},{\"OffersCount\":4,\"Id\":2,\"Name\":\"Alfresco - Four Points By Sheraton Pune\",\"Code\":\"AFS\",\"Status\":\"1\",\"Offers\":{\"Id\":3,\"Name\":\"10% Off on Food & Soft Beverages\"}},{\"OffersCount\":4,\"Id\":3,\"Name\":\"April Rain\",\"Code\":\"APR\",\"Status\":\"1\",\"Offers\":{\"Id\":4,\"Name\":\"10% Off on Lunch Buffet\"}}]"
      }
    ],
    [
      {
      "JSON_F52E2B61-18A1-11d1-B105-00805F49916B": "[{\"OffersCount\":4,\"Id\":1,\"Name\":\"@M The World Cuisine Restaurant Cocoon.\",\"Code\":\"MCC\",\"Status\":\"1\",\"Offers\":{\"Id\":1,\"Name\":\"50% Off on Wine\"}},{\"OffersCount\":4,\"Id\":1,\"Name\":\"@M The World Cuisine Restaurant Cocoon.\",\"Code\":\"MCC\",\"Status\":\"1\",\"Offers\":{\"Id\":2,\"Name\":\"30% Off on IMFL\"}},{\"OffersCount\":4,\"Id\":1,\"Name\":\"@M The World Cuisine Restaurant Cocoon.\",\"Code\":\"MCC\",\"Status\":\"1\",\"Offers\":{\"Id\":82,\"Name\":\"Gift Vouchers\"}},{\"OffersCount\":4,\"Id\":2,\"Name\":\"Alfresco - Four Points By Sheraton Pune\",\"Code\":\"AFS\",\"Status\":\"1\",\"Offers\":{\"Id\":3,\"Name\":\"10% Off on Food & Soft Beverages\"}},{\"OffersCount\":4,\"Id\":3,\"Name\":\"April Rain\",\"Code\":\"APR\",\"Status\":\"1\",\"Offers\":{\"Id\":4,\"Name\":\"10% Off on Lunch Buffet\"}}]"
      }
    ]
];



for(var i=0; i<result.length; i++){
  result[i] = result[i].map(function(obj){ 
      for(key in obj){
        if(obj.hasOwnProperty(key)){
          obj[key] = JSON.parse(obj[key].replace(/\\"/g, '"'));
        }
      }
      return obj;
    });
}

console.log(result);

对不起,我没有详细解释......我有点急着回去工作,所以如果有什么不清楚,请在评论部分提出问题。