dongxian6285 2014-10-08 15:46
浏览 34
已采纳

PHP 5.5升级破坏了这个简单的阵列/ JSON编码器

I just upgraded to 5.5.17 from 5.3.x and the following code stopped working (I get a blank response).

$gestr = mysql_query("SELECT name,age,id FROM users");
$star = array();
while($starid = mysql_fetch_array($gestr)){
     $star[] = array('name'=>$starid['name'],'age'=>$starid['age'],'id'=>$starid['id']);
}
$final=array('users'=>$star);
echo json_encode($final);

Please note that I have simplified the SQL statement, but I know it works all the way through the while loop because I can echo out $star[1][name] and it prints a user name.

  • 写回答

1条回答 默认 最新

  • dtt5830659 2014-10-08 16:18
    关注

    The issue was with json_encode not being able to parse a non-UTF8 encoded name. Thanks to @ChrisForrence for suggesting using json_last_error();

    The error was fixed by adding utf8_encode();

    $star[] = array('name'=>utf8_encode($starid['name']),'age'=>$starid['age'],'id'=>$starid['id']);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失