i have a JSON data in Javascript made form array using JSON.stringify
{
"user":"Mark",
"id":"80",
"0":["age","=","twenty four","varchar"],
"1":["prefix","=","Mr.","enum"]
}
i am sending this via AJAX to PHP file. When i echo the POST i get the values
echo (serialize($_POST['data']));
s:263:
"{
"user":"Mark",
"id":"80",
"0":["age","=","twenty four","varchar"],
"1":["prefix","=","Mr.","enum"]
}";
How can i get the POSTed data in an Array or Object. i have tried to do
var_dump(json_decode($_POST[‘data’]));
AND
var_dump(json_decode(serialize($_POST[‘data’])));
AND
var_dump(json_decode($_POST[‘data’],true));
but they did not work. Output is null.
json_decode() should do the trick for you, but depending on your server config (if magic_quotes_gpc is on), you might need to use stripslashes() before decoding.