Array to json string to array

Hello,

I’m having a PHP array which I json_encode. This array is used by a .js file.

Here’s how I do so far:


var myResult = JSON.parse(arrayJsonEncoded);

//outputs: result1,result2,result3								
alert(myResult);
								
myResultArray = myResult.split(",");

//would expect result2 but... nothing
alert(myResultArray[1]);

How do you retrieve an array from a json string?

Cheers.

:slight_smile:

Head along to json.org and at the end of the page you will see code libraries for a large number of languages.

For JavaScript, use json2.js

And if you don’t need to support IE7 and earlier then you can just use the JSON.stringify and JSON.parse methods without needing that script to define them as all modern browsers now have that JSON object built in (which is why that script first checks whether or not the JSON object exists - so that it can avoid overwriting the built in object that most browsers now have that provides the same functionality).