我正在开发一个Android应用程序,使用PHP与服务器进行交互。我正在使用000hosting免费服务器,当我将PHP从本地移动到服务器时,发生了有线连接。
这是使用手机的结果: 我在Logcat中输出结果。
Log.d(TAG, "RESULT: " + result);
D/GetNoteBackupsSummary: RESULT: <br />
System.err: org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONArray
为什么我得到<br />
作为结果?
浏览器的输出:
[{"id":"1","title":"nznnznss","content":"kzkzkzkzkz","date":"2018-10-06 23:02:50","backup_time":"2018-10-07 02:48:10"},
{"id":"2","title":"nznzksks","content":"nsnsnnsksks","date":"2018-10-06 23:02:45","backup_time":"2018-10-07 02:48:10"},
{"id":"3","title":"jzjsjsj","content":"nznzkzkzkz","date":"2018-10-06 23:02:40","backup_time":"2018-10-07 02:48:10"},
{"id":"4","title":"bsjsjsj ","content":"jsjsksk ","date":"2018-10-06 23:02:35","backup_time":"2018-10-07 02:48:10"}]
这是php代码:
session_start();
// $user_email = $_POST["user_email"];
// $time = $_POST["backup_time"];
$time = "2018-10-07 02:48:10";
$user_email = "ccc@ccc";
if (!$con) {
echo "Error: " . mysqli_connect_error();
exit();
}
$result = new \stdClass();
$out_put = array();
$table_name = getBackupUserTableName($user_email);
$sql = "SELECT * FROM ".$table_name." WHERE backup_time = '".$time."'";
if($query = mysqli_query($con, $sql)){
while ($row = mysqli_fetch_assoc($query))
{
array_push($out_put, $row);
}
print json_encode($out_put);
}else{
$result -> status = false;
$result -> error = mysqli_error($con);
print json_encode($result);
}
mysqli_close ($con);
在本地效果很好。 感谢任何帮助! 谢谢!