Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert JSON string to Javascript array [duplicate]

I have an array of arrays which I have planted in the DOM, so that I can reuse it at a later stage to transfer to the server:

[["1","aaaaaa","1"],["2","bbbbbbb","2"],["3","ccccccc","3"]]

If I would like to convert it back into a Javascript array, how would I go about doing this?

like image 484
Donal.Lynch.Msc Avatar asked Feb 23 '12 20:02

Donal.Lynch.Msc


3 Answers

var obj = $.parseJSON('[["1","aaaaaa","1"],["2","bbbbbbb","2"],["3","ccccccc","3"]]')

Assuming jquery is ok to use because of tag.

like image 126
jondavidjohn Avatar answered Nov 12 '22 09:11

jondavidjohn


If the browzer has the JSON object then

JSON.parse(string);

or if you have jQuery

$.parseJSON(string);
like image 58
zellio Avatar answered Nov 12 '22 09:11

zellio


var array = JSON.parse(my_JSON)
like image 17
user1106925 Avatar answered Nov 12 '22 07:11

user1106925