Home >Backend Development >PHP Tutorial >PHP JSON解析解决办法
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<br />(<br /> [name] => liux<br /> [sex] => 1<br /> [phone] => 13712800254<br /> [email] => [email protected]<br /> [town] => town_1<br /> [age] => 18<br /> [heigh] => 180<br /> [experience] => 工作经验<br />)<br /><br />