Possible Duplicate:
How to parse JSON easily?
I have this string:
[{text: 'First Option',  value: 'first'},{text: 'Second Option', value: 'second'},{text: 'Third Option',  value: 'third'}]
How do I convert it into an array/object in the same form in javascript?
Could either use var data = JSON.parse(yourString); or var data = eval('(' + yourString+ ')');
This is one of the times that eval actually comes in useful:
var x = eval(yourString);
But it's definitely safer to use JSON.parse as suggested by other answers.
Here's a working example of the eval version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With