I have a JSON encoded array that looks like this (it came from a 2d PHP string array):
[
[
"a1",
"a2",
"a3",
"a4"
],
[
"b1",
"b2",
"b3",
"b4"
],
[
"c1",
"c2",
"c3",
"c4"
]
]
It has been validated on http://jsonlint.com/
Now I want to send this array to another page by Ajax and convert it back to a 2d PHP array. After making a JSON array I do the following (where myJsonArray is the name I gave to the array after making it into a Javascript array.:
$.ajax({
type: "GET",
url: "somewhere.php",
data: {jsonArray : myJsonArray},
dataType: "json",
success: function(msg){
alert( msg);
}
});
}
And then in somewhere.php I do:
$json_array = $_GET['jsonArray'];
$myArray = json_decode($json_array,true);
But when I echo the result I just get
[Object object]
I'm not sure how to recreate the PHP array.
EDIT: How to make myJsonArray:
<?php
$array = json_encode($original_array);
echo "var myJsonArray = ". $array . ";\n";
?>
I would also like to point out that for tesitng purposes, in the alert box I made it print myJsonArray on success, and it did indeed print out the array as expected.
myJsonArray?