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);
myResultArray = myResult.split(",");
//would expect result2 but... nothing
How do you retrieve an array from a json string?
Head along to json.org and at the end of the page you will see code libraries for a large number of languages.
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).
This topic is now closed. New replies are no longer allowed.