Php
gettest.php:
$value ["Name"]= urlencode ("myname");
$value ["Pass"]= urlencode ("pass888");
$value ["Age"]=30;
$js _value = Json_encode ($value);
$url = "http://127.0.0.1:8080/get.php?id=100&value= $js _value";
$html = file_get_contents ($url);
Echo $html;
?>
get.php:
$x = Json_decode (UrlDecode ($_get["value"));
echo $x;
?>
Run in IE: http://127.0.0.1:8080/gettest.php
After the run is blank, you should be able to print out the JSON data
Reply to discussion (solution)
You echo $url in the gettest.php; See if the parameters are correct
Get.php is the object after Json_decode, so Echo $x; It's not proper.
Also do not need urldecode, you echo $_get["value"]; You can tell.
Echo $url in the gettest.php; The result is:
http://127.0.0.1:8080/get.php?id=100&value={"name": "MyName", "Pass": "pass888", "Age": 30}
In get.php, echo $_get["value"]; The result is:
{\ "name\": \ "myname\", \ "pass\": \ "pass888\", \ "age\": 30}
My goal is to get.php in the Jsong string to revert to a JSON object and print it out. So I changed the code.
The getp.php code is modified to:
$x = Json_decode (UrlDecode ($_get["value"));
echo $_get["value"];
Var_dump ($x);
?>
Display Yes: NULL. This doesn't seem to be right.
I call Json_encode in the same PHP file, Json_decode is fine. It's not going to work on different pages, I don't know how.
In get.php, echo $_get["value"]; The result is:
{\ "name\": \ "myname\", \ "pass\": \ "pass888\", \ "age\": 30}
Then you need stripslashes, not urldecode.
$x = Json_decode (stripslashes ($_get["value"));
Thank you so much.