gettest.php文件:
get.php文件如下:
注意:gettest.php,get.php文件的格式utf-8格式。
<?php
$value["name"]= urlencode("我的姓名");
$value["pass"]= urlencode("pass888");
$value["age"]=30;
$jsonstr =json_encode($value);
$url="http://127.0.0.1:8080/get.php?id=100&value=$jsonstr";
$html = file_get_contents($url);
echo $html;
?>
get.php文件如下:
<?php
$x = json_decode(stripslashes ($_GET["value"]), true);
echo urldecode($x["name"]);
echo urldecode($x["pass"]);
?>
在IE中输入:http://127.0.0.1:8080/gettest.php
输出:我的姓名pass888
注意:gettest.php,get.php文件的格式utf-8格式。
本文介绍了一个使用PHP通过GET请求传递JSON数据的例子。具体展示了如何构造和解析JSON字符串,涉及urlencode、json_encode及json_decode等函数的使用。
124

被折叠的 条评论
为什么被折叠?



