无法查看从MYSQL检索的数据,该数据使用PHP转换为JSON

时间:2018-01-28 17:04:27

标签: php mysql arrays json

我想查看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);

1 个答案:

答案 0 :(得分:1)

频繁,这是由于您的回复有重音:如果您的回复有重音(é,à等),json_encode将无法正常工作。

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