Search code examples
javascriptprototypejs

Converting a string to a JSON array using Prototype?


I have this json string:

{"17":{"31":{"price":5,"oldPrice":5,"priceValue":"5.0000","type":"fixed","excludeTax":5,"includeTax":5},"29":{"price":8,"oldPrice":8,"priceValue":"8.0000","type":"fixed","excludeTax":8,"includeTax":8},"30":{"price":10,"oldPrice":10,"priceValue":"10.0000","type":"fixed","excludeTax":10,"includeTax":10}},"12":{"price":0,"oldPrice":0,"priceValue":"0.0000","type":"fixed","excludeTax":0,"includeTax":0},"11":{"price":0,"oldPrice":0,"priceValue":"0.0000","type":"fixed","excludeTax":0,"includeTax":0}}

How can I convert this to an array using Prototype? I tried evalJSON(), but it did not work.


Solution

  • Built-in JSON.parse should do it,you don't need any library:

    var obj = JSON.parse(jsonString);