PHP头条
热点:

PHP不同页面间传递json的有关问题


PHP不同页面间传递json的问题
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;
?>

在IE中运行: http://127.0.0.1:8080/gettest.php
运行后得到的是空白,应该能把json的数据打印出来吧 PHP 分享到:
------解决方案--------------------
在get.php中, echo $_GET["value"];   结果是:
{\"name\":\"myname\",\"pass\":\"pass888\",\"age\":30} 

那么就需要 stripslashes 而不是 urldecode
$x =  json_decode(stripslashes($_GET["value"]));

www.phpzy.comtrue/phprm/5970.htmlTechArticlePHP不同页面间传递json的有关问题 PHP不同页面间传递json的问题 gettest.php: $value["name"]=urlencode("myname"); $value["pass"]=urlencode("pass888"); $value["age"]=30; $js_value=json_encode($value); $url="http://127.0.0.1:...

相关文章

相关频道:

PHP之友评论

今天推荐