0

Android アプリでエラーが発生し、JSONException実行するたびにエラーが発生します。

これは私の PHP コードで、テーブル内のtypeのすべての値が'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