0

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

[
  [
    {
      "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\"}}]"
    }
  ]
]
4

1 回答 1

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);

抱歉,没有详细解释……我有点急着回去工作,所以如果有什么不清楚的地方,请在评论部分提出问题。

于 2016-08-16T17:08:46.910 回答