phpmysql生成json中文乱码
求解决,代码如下:<?php$mysql_db_hostname="localhost";$mysql_db_user="root";$mysql_db_password...
求解决,代码如下:
<?php
$mysql_db_hostname = "localhost";
$mysql_db_user = "root";
$mysql_db_password = "==";
$mysql_db_database = "==";
$con = @mysqli_connect($mysql_db_hostname, $mysql_db_user, $mysql_db_password,
$mysql_db_database);
if (!$con) {
trigger_error('Could not connect to MySQL: ' . mysqli_connect_error());
}
$var = array();
$sql = "SELECT id , title FROM dede_archives";
$result = mysqli_query($con, $sql);
while($obj = mysqli_fetch_object($result)) {
$var[] = $obj;
}
echo '{"data":'.json_encode($var).'}';
?>
访问php得到的数据如下:
{"data":[{"id":"1","title":"\u638f\u4e2a\u8033\u7ed3\u77f3\u9700\u82b1\u8d391000\u5143\uff1f\u4e13\u5bb6\uff1a\u8033\u7ed3\u77f3\u8fd9\u4e2a\u8bf4\u6cd5\u4e0d\u5b58\u5728"},{"id":"2","title":"\u9057\u7231\u6e56\u8fb9\uff0c\u591c\u5e02\u644a\u70b9\u6446\u5230\u4e86\u9a6c\u8def\u4e0a"}]} 展开
<?php
$mysql_db_hostname = "localhost";
$mysql_db_user = "root";
$mysql_db_password = "==";
$mysql_db_database = "==";
$con = @mysqli_connect($mysql_db_hostname, $mysql_db_user, $mysql_db_password,
$mysql_db_database);
if (!$con) {
trigger_error('Could not connect to MySQL: ' . mysqli_connect_error());
}
$var = array();
$sql = "SELECT id , title FROM dede_archives";
$result = mysqli_query($con, $sql);
while($obj = mysqli_fetch_object($result)) {
$var[] = $obj;
}
echo '{"data":'.json_encode($var).'}';
?>
访问php得到的数据如下:
{"data":[{"id":"1","title":"\u638f\u4e2a\u8033\u7ed3\u77f3\u9700\u82b1\u8d391000\u5143\uff1f\u4e13\u5bb6\uff1a\u8033\u7ed3\u77f3\u8fd9\u4e2a\u8bf4\u6cd5\u4e0d\u5b58\u5728"},{"id":"2","title":"\u9057\u7231\u6e56\u8fb9\uff0c\u591c\u5e02\u644a\u70b9\u6446\u5230\u4e86\u9a6c\u8def\u4e0a"}]} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询