我需要编码一些json-越南字。我尝试使用JSON_UNESCAPED_UNICODE,但看起来不再起作用。
header("Content-type: application/json; charset=utf-8");
$db = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD,DB_DATABASE) or die(mysqli_connect_errno());
$result = mysqli_query($db,"SELECT * FROM categories") ;
if (mysqli_num_rows($result) > 0) {
$response["categories"] = array();
while ($row = mysqli_fetch_array($result)) {
$categories["id"] = json_encode($row["id"]);
$categories["name"]= json_encode($row["name"],JSON_UNESCAPED_UNICODE);
array_push($response["categories"], $categories);
}
$response["result"] = "OK";
$myJSON = json_encode($response);
echo $myJSON;
}
输入:
id = 1名称=特鲁伊恩(TruyệnCổTích)
输出:
id = 1名称= false
这是我第一次尝试PHP。我的PHP版本是7.2.8。
答案 0 :(得分:0)
mysqli_query('SET NAMES utf8')
。json_last_error()
打印错误信息答案 1 :(得分:0)
您必须配置连接SQL以便对其进行编码mysqli_set_charset($con,"utf8");