php - 使用 json_encode 函数时为空 json 字符串

标签 php mysql json

我在 php 中使用 json_encode() 函数遇到了一个非常奇怪的问题。我有 2 个包含数据的表。在表 1 中只有 2 行。使用下面的代码可以很好地与 json_encode() 函数一起使用。在表 2 中,我目前有 50,000 行,我从中选择(例如 1000)行。使用相同的代码不会将我引向 json 字符串。

我使用的代码是这样的:

$array = array();
while($row = mysqli_fetch_assoc($result)) {
    $array[] = $row;
}
echo count($array);
echo json_encode($array);

如何让 json_encode() 也为第二个表(更大的表)工作?

最佳答案

我找到了问题的答案:我必须将整个编码结构更改为 UTF-8。所以我改变了:

  • 数据库编码为 UTF-8(在 PhpMyAdmin 中)
  • 编码为 UTF-8 的表格(在 PhpMyAdmin 中)
  • 使用$connection->set_charset("utf8");的连接编码
  • 填充数据库(获取和发布数据)的 java 程序中的 url 编码

关于php - 使用 json_encode 函数时为空 json 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34251710/

相关文章:

javascript - PHP 评分系统,无需数据库

javascript - 将 id 值传递给 ajax 页面

php - 使用 php 从 mysql 下载页面获取 PDF 文件

javascript - javascript 中的 json 数组搜索

java - 安卓 : getting multiple data in listview from server in another screen using Json

javascript - 如何从 json 文件加载多个标记?

php - 如何从php正确调用jquery函数?

php - 将 iFrame 内容保存到 html 文件?

php - 确定 sql 语句返回 true 还是 false 的正确方法是什么?

MYSQL: ALTER TABLE DROP FOREIGN KEY 基于 SELECT 结果