doudao1950 2015-12-03 12:20
浏览 52
已采纳

PHP JSON编码为utf8并打印它

The following is my php script:

<?php


$con = $con = mysql_connect("localhost","root","");
mysql_set_charset('utf8',$con);

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("ninelifes", $con);

$result = mysql_query("SELECT * FROM quotes ORDER BY quotations DESC LIMIT 21,1");

while($row = mysql_fetch_assoc($result))
  {
    $output[]= $row;
  }

print json_encode($output);

mysql_close($con);


?>

This is the print:

enter image description here

The "\u00e4" is a "ä". Well, the question is how can is solve the utf8 decoding for my json print?

  • 写回答

1条回答 默认 最新

  • douao3636 2015-12-03 12:22
    关注

    Try this:

    print json_encode($output, JSON_UNESCAPED_UNICODE);
    

    Read more about json_encode() parameters.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)