1

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 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

neil
  • 11
  • 2
  • So `{\"type\":\"value\"}` is what you get when you do `echo $_GET['echo']` ? Have you tried to use `json_decode`? – Felix Kling Dec 11 '10 at 21:08

2 Answers2

2

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

StasM
  • 10,593
  • 6
  • 56
  • 103
0

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.

Raphael Ayres
  • 864
  • 6
  • 16