【发布时间】:2016-04-24 12:03:40
【问题描述】:
我创建了一个 CMS 并在 localhost 中对其进行了测试并读取了所有 json 响应。但是,当我将代码放入实时服务器时,我仍然可以 insert、view 和 edit 数据,但我无法读取任何 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 常量
-
是的!!!它现在正在工作!:) 谢谢