最新赞助活动温馨提示:自愿赞助服务器费用,学生和没有工作的整站资源免费下载!
头像

PHP JSON解析解决办法

来源:http://erdangjiade.com/topic/79736.html 你好,世界。 2017-10-04 21:03浏览(1)

PHP JSON解析
up_user_info={"name":"liux","sex":"1","phone":"13712800254","email":"[email protected]","town":"town_1","age":"18","heigh":"180","experience":"工作经验"}

$up_user_info = $_POST['up_user_info'];
if($up_user_info == null){
$error = 1;
}
$upuser_decode = json_decode($up_user_info,true);
$name = $upuser_decode['name'];


echo $name;


输出为空~~为什么...想来想去都不知道哪里有错!
------解决方案--------------------
你是说 $_POST['up_user_info'] = '{"name":"liux","sex":"1","phone":"13712800254","email":"[email protected]","town":"town_1","age":"18","heigh":"180","experience":"工作经验"}';
print_r(json_decode($_POST['up_user_info'])); 为空?

那说明你是在 gbk 环境下
print_r(json_decode(iconv('gbk', 'utf-8', $_POST['up_user_info'])));
就可以了
stdClass Object
(
[name] => liux
[sex] => 1
[phone] => 13712800254
[email] => [email protected]
[town] => town_1
[age] => 18
[heigh] => 180
[experience] => 工作经验
)


------解决方案--------------------
你可以這樣測試
1.$up_user_info是post過來的
2.使用我上面的程序

分別測試是否可以輸出。

如果1不行 2可以,就是POST過來的數據有問題,請檢查這裡的數據。

评论0
头像

友情提示:垃圾评论一律封号 加我微信:826096331拉你进VIP群学习群

1 2