0

Possible Duplicate:
Why the open quote and bracket for eval('(' + jsonString+ ')') when parsing json string

var JSON = {
    "offers": [
        {
            "targetURL": "http://www.whotels.com/playinplansmobile?language=en_US",
            "title": "WHO PUTS THE PLAY IN YOUR PLANS?",
            "stayStartDate": "Feb 08, 2010",
            "stayEndDate": "Dec 31, 2011",
            "offerName": "WHO PUTS THE PLAY IN YOUR PLANS?",
            "expirationDate": "Dec 22, 2011",
            "htmlLongDesc": " <p>Getaway with a hot W Hotels escape. Your W Hotels Play experience includes two cool cocktails, daily parking, and a Wonderful Room youll love at a wow-worthy rate! Book now for Play dates all year long, through December 22, 2011.</p>",
            "effectiveDate": "Feb 07, 2010",
            "offerCode": "WPLAY",
            "businessValue": "90",
            "propIds": "1114,1153,1154,1234,1299,1300,1433,1471,1521,1522,1599,1736,1785,1788,1789,2005,2030,3019,3131,3154,3167,3224,97502,97508,97509,97518",
            "media": "/en_US/Media/Graphics/Brands/W/Images/specialOffers/Opening_Offer_LP_Austin_03224_final.jpg"
        },
        {
            "targetURL": "http://www.starwoodpromos.com/bettertomorrows50/?IM=SPG_7792944SS_4P_MX_NAD&language=en_US&language=en_US",
            "title": "Save 40% off on your next night.",
            "stayStartDate": "Jan 14, 2009",
            "stayEndDate": "Dec 30, 2011",
            "offerName": "Save 40% off on your next night.",
            "expirationDate": "Dec 30, 2011",
            "htmlLongDesc": " <p>Better tomorrows are on us.  For every night you stay at our regular rate, you get the next night at 40% off, now through December 31, 2010.</p>",
            "effectiveDate": "Jan 13, 2009",
            "offerCode": "bettertomorrowsmobile",
            "businessValue": "80",
            "propIds": "123,208,212,213,217,304,364,639,645,653,661,671,712,742,744,749,752,761,778,786,817,818,822,849,856,862,879,913,917,930,949,990,1126,1141,1142,1151,1156,1165,1168,1180,1203,1223,1237,1243,1256,1257,1260,1263,1270,1329,1355,1357,1387,1408,1473,1476,1481,1490,1504,1515,1538,1544,1548,1561,1567,1580,1587,1592,1712,1730,1731,1748,1758,1775,1980,1989,1994,3038,3040,3061,3063,3064,3109,3122,3194,97506",
            "media": "/en_US/Media/Graphics/Brands/W/Images/specialOffers/MB_bettertomorrowsmobile.jpg"
        }
    ]
}

The above is the JSON string that I am trying to convert into an object. It properly gets converted into Object when i use eval(JSON), but when I use eval('('+JSON+')'), it throws "missing ] after element list". I am trying to understand what is the difference between both.

Community
  • 1
  • 1
Kanth
  • 11
  • … and don't use `eval` for this. [Get a real JSON parser](https://github.com/douglascrockford/JSON-js/). – Quentin Jul 25 '11 at 06:36
  • First of all, your choice of 'JSON' as a local variable name is the worst thing you could do, because JSON is already the name of the global JSON object. – Tom Robinson Mar 10 '12 at 05:29
  • 9sorry I hit Enter by mistake) – Tom Robinson Mar 10 '12 at 05:39
  • The code yow have written already creates the object you want. There is no need for you to parse it, because your Javascript code has already been parsed. It was already valid Javascript years before the term "JSON" was invented. You only need to eval or parse a JSON string if it comes from another source, such as an AJAX request. – Tom Robinson Mar 10 '12 at 05:59

0 Answers0