类型为java.lang.String的Android数据库无法转换为JSONObject

I got the error on this line:

JSONObject jsonResponse = new JSONObject(response);

Which I think there is error on the PHP file. But I cannot figure out what is the problem in my PHP code.

<?php
    require "init.php";
    require "password.php";

    $username = $_POST["username"];
    $password = $_POST["password"];

    $statement = mysqli_prepare($con, "SELECT * FROM User WHERE username = ?");
    mysqli_stmt_bind_param($statement, "s", $username);
    mysqli_stmt_execute($statement);
    mysqli_stmt_store_result($statement);
    mysqli_stmt_bind_result($statement, $colNo, $colUsername, $colPassword, $colName, $colHpno, $colUser_state);

    $response = array();
    $response["success"] = false;  

    while(mysqli_stmt_fetch($statement)) {
        if (password_verify($password, $colPassword)) {
            $response["success"] = true;
            $response["username"] = $colUsername;
            $response["name"] = $colName;
            $response["hpno"] = $colHpno;
        } 
    };

    echo json_encode($response);
?>

Some people told me that I got the wrong order for the mysqli_stmt_bind_result, but I have followed the order in the database table.

LOGCAT:

04-15 11:06:30.319 16826-16826/wqyap762.rprqs W/System.err: org.json.JSONException: Value <br><h3>Database of type java.lang.String cannot be converted to JSONObject
04-15 11:06:30.319 16826-16826/wqyap762.rprqs W/System.err:     at org.json.JSON.typeMismatch(JSON.java:111)
04-15 11:06:30.319 16826-16826/wqyap762.rprqs W/System.err:     at org.json.JSONObject.<init>(JSONObject.java:160)
04-15 11:06:30.319 16826-16826/wqyap762.rprqs W/System.err:     at org.json.JSONObject.<init>(JSONObject.java:173)
04-15 11:06:30.319 16826-16826/wqyap762.rprqs W/System.err:     at wqyap762.rprqs.LoginActivity$3.onResponse(LoginActivity.java:91)
04-15 11:06:30.319 16826-16826/wqyap762.rprqs W/System.err:     at wqyap762.rprqs.LoginActivity$3.onResponse(LoginActivity.java:86)
04-15 11:06:30.319 16826-16826/wqyap762.rprqs W/System.err:     at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:60)
04-15 11:06:30.319 16826-16826/wqyap762.rprqs W/System.err:     at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30)
04-15 11:06:30.319 16826-16826/wqyap762.rprqs W/System.err:     at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
04-15 11:06:30.319 16826-16826/wqyap762.rprqs W/System.err:     at android.os.Handler.handleCallback(Handler.java:739)
04-15 11:06:30.319 16826-16826/wqyap762.rprqs W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:95)
04-15 11:06:30.319 16826-16826/wqyap762.rprqs W/System.err:     at android.os.Looper.loop(Looper.java:135)
04-15 11:06:30.319 16826-16826/wqyap762.rprqs W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5254)
04-15 11:06:30.319 16826-16826/wqyap762.rprqs W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
04-15 11:06:30.319 16826-16826/wqyap762.rprqs W/System.err:     at java.lang.reflect.Method.invoke(Method.java:372)
04-15 11:06:30.319 16826-16826/wqyap762.rprqs W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
04-15 11:06:30.319 16826-16826/wqyap762.rprqs W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
查看全部
douyu9433
douyu9433
2016/04/15 03:23
  • android
  • json
  • php
  • mysql
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复