开发者

Javascript Object to Json. PHP can't decode serialized JSON

开发者 https://www.devze.com 2023-04-05 15:54 出处:网络
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.

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']))
0

精彩评论

暂无评论...
验证码 换一张
取 消