• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

php json转数组出错

php 搞代码 3年前 (2022-01-24) 23次浏览 已收录 0个评论

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

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

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

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

3:将json转换成数组

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

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

发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址