0

我在我的 Android 应用程序上遇到错误,JSONException每次运行它都会抛出一个错误。

这是我的 PHP 代码,如果我的表中的每个类型值都等于'run' ,它只会返回 true :

$userId = $_POST["userId"]; 
$statement = mysqli_prepare($con, "SELECT type FROM performance WHERE userId = ?");
mysqli_stmt_bind_param($statement, "i", $userId);
mysqli_stmt_execute($statement);
mysqli_stmt_store_result($statement);
mysqli_stmt_bind_result($statement,  $type);
$correct = false;  
while(mysqli_stmt_fetch($statement)){
    if(strcmp($type,"run")==0)     $correct = true;
    else     $correct = false;
}
mysql_close($statement);
echo json_encode($correct);

这是我的 Android 代码,我正在使用 Volley 库:

Response.Listener<String> responseListener = new Response.Listener<String>(){
    @Override
    public void onResponse(String response) {
        try {
            JSONObject jsonResponse = new JSONObject(response);
            boolean success = jsonResponse.getBoolean("correct");
            if (success)
                /*do something*/
            else
                /*do something else*/
        }catch (JSONException e) {
            e.printStackTrace();
        }    
    }    

但是,每次我运行我的应用程序时都会调用 JSONException,它会说

org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject

谁能帮我?

4

0 回答 0