Javascript Object to Json. PHP can't decode serialized JSON
I have a javascript object which I am encoding to Json and s开发者_StackOverflow社区ending data to PHP. Unfortunately, PHP can't decode JSON string to array. I am lost at this point.
Jquery
sendData = {city: 48, fullName: 'John'};
sendData = JSON.stringify(sendData);
$.get("ajax/getter.php", { get: "info", data: sendData },function(data){
// DO STH with returned data
});
OUTPUT : {"city":48,"fullName":"John"}
PHP part
<?php
$data = $_GET['data'];
$data = json_decode($data);
var_dump($data);
?>
OUTPUT : NULL
I will be glad if anyone could show me where I am doing wrong.
You must have magic_quotes_gpc
enabled and in $_GET['data']
, all "
chars are escaped.
Disable magic_quotes_gpc
. If you can't, use stripslashes
:
$data = json_decode(stripslashes($_GET['data']))
精彩评论