开发者

PHP problem decoding GET parameter with double quotes

I'm passing a 'data' parameter to a php page using AJAX. The parameter is a JSON string like:

{"type":"value"}

I encode with encodeURIComponent开发者_如何学JAVA JS function getting:

%7B%22type%22%3A%22value%22%7D

If I write by hand:

http://some_url/index.php?data=%7B%22type%22%3A%22value%22%7D

my "index.php" simply gets the parameters and "prints in the screen". The problem is I'm getting this which isn't a valid JSON to decode:

{\"type\":\"value\"}

Any help, thanks in advance


Check that you don't have magic_quotes on. The use json_decode() to decode your JSON data.


Do like this. Replace de "\" from the parameter.

$jsonString = $_GET['data'];

$jsonStringReplaced = str_replace("\\","",$jsonString);

$arr = json_decode($jsonStringReplaced);

var_dump($arr);

It worked for me.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜