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

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.

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

报告相同问题?