首页 / JSON / phpjson转数组出错
phpjson转数组出错
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了phpjson转数组出错,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2157字,纯文字阅读大概需要4分钟。
内容图文
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<strlen($json);$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
分享到:
------解决方案--------------------
没有问题呀
$s = '{"mecdoctor":[{"doctorId":"","doctorName":"XXXX", "doctorprice":"122","expertise":"XXXXX","departments":"医内科","doctorTitle":"主任医师","doctorPhoto":"hmh"}]}';
print_r(_json_decode($s));
function _json_decode($json){
$comment = false;
$out = '$x=';
for ($i=0; $i<strlen($json);$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;
}
Array
(
[mecdoctor] => Array
(
[0] => Array
(
[doctorId] =>
内容总结
以上是互联网集市为您收集整理的phpjson转数组出错全部内容,希望文章能够帮你解决phpjson转数组出错所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。