我有一个javascript对象,我编码Json和发送数据到PHP。不幸的是,PHP无法将JSON字符串解码为数组。在这一点上我迷路了。
JquerysendData = {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
$data = $_GET['data'];
$data = json_decode($data);
var_dump($data);
?>
输出: NULL
如果有人能告诉我我哪里做错了,我将很高兴。
必须启用magic_quotes_gpc
,并且在$_GET['data']
中,所有"
字符都被转义。
禁用magic_quotes_gpc
。如果不能,使用stripslashes
:
$data = json_decode(stripslashes($_GET['data']))