php - JSON 将 Cyryllic 编码为 null

标签 php mysql json cyrillic

我有带有西里尔字母符号的 MYSQL 表。
This is my MYSQL table

我使用 PHP 获取 MYSQL 结果并将其编码为 JSON。

    <?php

include 'connection.php';

$array_to_json = array();

$query = "SELECT * FROM online";


$result = mysqli_query($link, $query);

mysqli_set_charset("utf8");
while($row = $result->fetch_assoc()) {

$row_array['parameters'] = $row['parameters'];

$row_array['Descriptions'] = $row['Descriptions'];

$row_array['units'] = $row['units'];
      array_push($array_to_json, $row_array);

}

echo json_encode($array_to_json, JSON_UNESCAPED_UNICODE);

$result->close();

?>

结果我得到了 null。 JSON returns null

我做错了什么?

最佳答案

您尝试过使用

    $row_array['parameters']    = base64_encode($row['parameters']);
    $row_array['Descriptions']  = base64_encode($row['Descriptions']);
    $row_array['units']         = base64_encode($row['units']);
    array_push($array_to_json, $row_array);

关于php - JSON 将 Cyryllic 编码为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39486591/

相关文章:

php - AUTO_INCREMENT lastInsertId - 我的还是服务器的?

java - MySQL语法错误Java表创建

PHP Echo Mysql 数据来自 2 个表 BY 最新数据

javascript - 从复杂的 JSON 对象打印每个 JSON 输入路径

java - 在 Java 中将具有无效 XML 字符的任意 JSON 转换为 XML

php - 检查提交值是否在数组中?

php - 为什么从 CRON 运行 php 脚本会导致字符编码问题?

php - php中的图像旋转和白色背景

MySQL安装问题 mysql-5.7.18-linux-glibc2.5-x86_64.tar

php - 想在php中发送和接收json数据