Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android截取、php、mysql xampp中显示的JSONException_Php_Android_Mysql - Fatal编程技术网

android截取、php、mysql xampp中显示的JSONException

android截取、php、mysql xampp中显示的JSONException,php,android,mysql,Php,Android,Mysql,我正在从事一个android项目。我的登录活动有问题。 由于没有将字符串转换为JSONObject,我得到了JSONException,并且连接超时错误。 我使用的是安卓截击库,MySQL XAMPP服务器 这是我的 Login.php <?php include("Connection.php"); if(isset($_POST["email"]) && isset($_POST["password"])) { $email=$_POST["emai

我正在从事一个android项目。我的登录活动有问题。 由于没有将字符串转换为JSONObject,我得到了JSONException,并且连接超时错误。 我使用的是安卓截击库,MySQL XAMPP服务器

这是我的 Login.php

    <?php

include("Connection.php");

if(isset($_POST["email"]) && isset($_POST["password"]))
{

   $email=$_POST["email"];

   $password=$_POST["password"];

   $result = mysqli_query($conn, "select * from user_master where email='$email' && password='$password'");

    if(mysqli_num_rows($result) > 0)
    {   
        echo "success";
        exit;
    }           
    else
    {   
        echo "INVALID";
        exit;
    }
}


?>
用这行代码

JSONObject jsonObject = new JSONObject(response);

您试图将响应读取为Json,但响应根本不是Json。请与postman一起打开您的php页面,这样您就可以看到收到的响应并正确理解问题

当您的php服务器返回信息时,是字符

success

但是,如果您尝试将这些值解析为JSON,您将失败

JSON.parse("success")
09:59:02.442 VM271:1 Uncaught SyntaxError: Unexpected token a in JSON at position 0
    at JSON.parse
有效的JSON值为

因此,您可以将PHP服务器修复为回显字符串、数字、数组、对象、true、false或null,如下所示

if(mysqli_num_rows($result) > 0)
{   
    echo '"success"';
    exit;
}           
else
{   
    echo '"INVALID"';
    exit;
}
INVALID
JSON.parse("success")
09:59:02.442 VM271:1 Uncaught SyntaxError: Unexpected token a in JSON at position 0
    at JSON.parse
if(mysqli_num_rows($result) > 0)
{   
    echo '"success"';
    exit;
}           
else
{   
    echo '"INVALID"';
    exit;
}