我的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
任何人都可以帮助我吗?