【问题标题】:Backend JSON response后端 JSON 响应
【发布时间】:2016-04-24 12:03:40
【问题描述】:

我创建了一个 CMS 并在 localhost 中对其进行了测试并读取了所有 json 响应。但是,当我将代码放入实时服务器时,我仍然可以 insertviewedit 数据,但我无法读取任何 json回应。这是一个至关重要的部分,因为我的 android 应用程序需要它们。

这是我的代码。

<?php
include ("../includes/connect.php");

$string = "";
$newString = "";
$get_posts = "select * from last_game";
$run_posts = mysqli_query($con, $get_posts);
$posts_array = array();

while ($posts_row = mysqli_fetch_array($run_posts))
{
  $row_array['id'] = $posts_row['id'];
  $row_array['game'] = $posts_row['game'];
  $row_array['date'] = $posts_row['date'];
  array_push($posts_array, $row_array);
}

$string = json_encode($posts_array, JSON_UNESCAPED_UNICODE);
echo $string;
?>

我得到的错误是

Notice: Use of undefined constant JSON_UNESCAPED_UNICODE - assumed 
'JSON_UNESCAPED_UNICODE' in /var/www/vhosts/theo-
 android.co.uk/httpdocs/manudb/android/last_game_json.php on line 26

Warning: json_encode() expects parameter 2 to be long, string given in    
/var/www/vhosts/theo-
android.co.uk/httpdocs/manudb/android/last_game_json.php on line 26

会不会是php版本有问题?

有什么想法吗?

谢谢。

【问题讨论】:

  • 如果没有看到您遇到的错误,我们将无法帮助您...检查浏览器的开发人员控制台是否有 JS 错误或服务器是否有 PHP 错误(如果它们设置为不显示)
  • 移除 JSON_UNESCAPED_UNICODE 常量
  • 是的!!!它现在正在工作!:) 谢谢

标签: php mysql json server


【解决方案1】:

可能您的 MySQL 连接在实时服务器上需要不同的凭据: 检查您的 connect.php 以确保 mysql 主机/用户/密码和数据库名称正确。

您可以通过手动将浏览器指向远程服务器并查看发生了什么来检查服务器响应,可能您应该使用以下方式启用调试: error_reporting(E_ALL); ini_set("display_errors", 1);

重要提示:请记住在投入生产时删除这些行!

【讨论】:

  • 把你建议的代码行后,我得到这个错误。
  • 注意:在第 26 行的 /var/www/vhosts/theo-android.co.uk/httpdocs/manudb/android/last_game_json.php 中使用未定义的常量 JSON_UNESCAPED_UNICODE - 假定为“JSON_UNESCAPED_UNICODE”警告: json_encode() 期望参数 2 很长,字符串在第 26 行的 /var/www/vhosts/theo-android.co.uk/httpdocs/manudb/android/last_game_json.php 中给出
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-01-24
  • 2020-03-04
  • 2021-08-20
  • 2016-04-10
  • 1970-01-01
  • 1970-01-01
  • 2019-05-03
相关资源
最近更新 更多