Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String to JSON array

Status
Not open for further replies.

musicmannz

Programmer
May 5, 2006
2
NZ
Hi

If I have a string that looks like e.g.

[['line1',line2'],['line3','line4']]

How can I turn this into a JSON array? The split() method doesn't work...
 
This would be one of the few occassions I would actually promote the use of "eval":

Code:
var myArrayString = "[['line1', 'line2'], ['line3', 'line4']]";
var myArray = eval(myArrayString);
alert(myArray.length); // should return 2
alert(myArray[1][1]);   // should return 'line4';

Hope this helps,
Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top