PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

php json转数组出错

原创
2016-06-13 11:36:43 794浏览

php json转数组出错求助
1:先输出json


//组合医生信息JSON
$jsonDoctorInfo = "{\"mecdoctor\":[";
$jsonDoctorInfo .= "{\"doctorId\":\"".$doctorId."\",\"doctorName\":\"".$strDoctorName."\", \"doctorprice\":\"".$strPrice."\",\"expertise\":\"".$strExpertise."\",\"departments\":\"".$strdepartments."\",\"doctorTitle\":\"".$strTitle."\",\"doctorPhoto\":\"".$strDoctorPhoto."\"}";
$jsonDoctorInfo .= "]}";

2:获取并decode
$jsonGetDoctorInfoData = json_encode($jsonGetDoctorInfoData);
$objGetDoctorInfoData  = json_decode($jsonGetDoctorInfoData);
输出:

{"mecdoctor":[{"doctorId":"","doctorName":"XXXX", "doctorprice":"122","expertise":"XXXXX","departments":"医内科","doctorTitle":"主任医师","doctorPhoto":"hmh"}]}


3:将json转换成数组

//解析JSON数据
function _json_decode($json){
$comment = false;
$out = '$x=';
for ($i=0; $i if (!$comment){
if ( ($json[$i] == '{') || ($json[$i] == '[') )
$out .= ' array(';
else if (($json[$i] == '}') || ($json[$i] == ']'))
$out .= ')';
else if ($json[$i] == ':')
$out .= '=>';
else
$out .= $json[$i];
}else
$out .= $json[$i];
if($json[$i]== '"' && $json[($i-1)]!="\\")
$comment = !$comment;
}
eval($out.";");

return $x;
}

4:出现问题
Parse error: syntax error, unexpected T_DOUBLE_ARROW in /home/u945504094/public_html/config/config.inc.php(876) : eval()'d code on line 1


声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。