I have a JSON string that I would like to convert to a javascript array. How can I do this?
I was under the impression thot JQuery could do this
asked May 23, 2011 at 15:53
KevinDeus
12.2k20 gold badges68 silver badges97 bronze badges
2 Answers 2
in general you can do JSON.parse(jsonString). Most browsers support this.
with jquery, if you tell $.ajax() that the response type is json, it will do this for you. See the 'dataType' option here http://api.jquery.com/jQuery.ajax/
answered May 23, 2011 at 15:55
hvgotcodes
121k33 gold badges209 silver badges237 bronze badges
Comments
lang-js
{ "x": "y" }, how exactly do you want to "convert" that to an array? You can parse it, and then store the object in an array if you want to, I guess, but without more explanation it's hard to know exactly what you're trying to achieve.