2016-08-16 26 views
0

如何一次性獲取數據,而無需數據?Jsondata以塊形式返回並附帶/附加

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

回答

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

對不起這不是精心解釋......我有點着急要回工作,所以如果有任何不明確的地方,請在評論部分留下問題。

+0

1)當我在控制檯中記錄響應時,1)結果似乎是完美的,沒有附加任何「\」2)還有任何方法來獲得數據在一起,而不是上述的chuks –

+0

我不明白問題2。沒有包含關於如何獲取數據或如何存儲數據的代碼,所以我無法提供幫助。如果這個答案解決了你原來的問題,請接受它。謝謝 – kennasoft