0

How to get data in one go without / in data?

[
  [
    {
      "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\"}}]"
    }
  ]
]
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Vaibhav Ramteke
  • 183
  • 1
  • 1
  • 6

1 Answers1

0

Sql Server probably has those values escaped in order to safely persist them as strings. If the JSON parser fails to unescape them, you may have to escape them yourself like this:

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

Sorry it's not elaborately explained... I'm kinda in a hurry to get back to work, so if anything is not clear, drop a question in the comments section.

kennasoft
  • 1,595
  • 1
  • 14
  • 26
  • 1) When I log the response in the console the 1) result seems be perfect without any "\" appended 2) Also any way to get data together instead of chuks as above – Vaibhav Ramteke Aug 17 '16 at 08:44
  • I don't understand question 2. You didn't include code on how you get the data or how you store the data, so I can't help much. If this answer solves your original question, pls accept it. Thanks – kennasoft Aug 17 '16 at 09:50