【问题标题】:Can't View data retrieved from MYSQL which is converted into JSON using PHP无法查看从使用 PHP 转换为 JSON 的 MYSQL 检索的数据
【发布时间】:2018-07-07 10:09:51
【问题描述】:

我想查看由 SQL 语句检索到的数据,但仅在执行此操作时 json_response 显示数据 但我想看到的是 echo json_encode($json_response) 格式的数据。
我按照本教程进行操作,但没有得到相同的结果。
json_encode($json_response) 不显示数据 AKA 纯屏幕
http://www.webslesson.info/2016/05/convert-data-from-mysql-to-json-formate-using-php.html

$query = "SELECT * from LibraryEvents";

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

  $json_response = array();
  while($row = mysqli_fetch_assoc($result)) {
        $json_response[] = $row;
        //array_push($json_response,$row_array);
  }

  echo '<pre>';
  print_r($json_response);
  echo '<pre>';
  echo json_encode($json_response);

【问题讨论】:

  • 那么,你看到的输出是什么?
  • print_r($json_response) 显示所有数据,但 echo json_encode($json_response) 不显示数据
  • LibraryEvents 表中是否插入了任何数据?
  • 有数据,因为我确实说过 print_r 显示数据但 json_encode 不显示任何内容
  • $connDB = mysqli_connect("localhost","user","pass","database");你的 $connDB 是对的吗?

标签: php mysql arrays json


【解决方案1】:

频繁,这是由于您的响应带有重音符号:如果您的响应带有重音符号(é、à 等),json_encode 将无法正常工作。

这可能会对您有所帮助:How to json_encode array with french accents?

【讨论】:

  • 谢谢。你的回答解决了问题。用重音换词后,一切都解决了。
猜你喜欢
  • 1970-01-01
  • 2016-02-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-14
相关资源
最近更新 更多