【发布时间】:2017-02-08 13:55:05
【问题描述】:
org.json.JSONException: No value for Success
org.json.JSONException: No value for Success
W/System.err: at org.json.JSONObject.get(JSONObject.java:389)
W/System.err: at org.json.JSONObject.getBoolean(JSONObject.java:410)
我收到此错误,它不会从我的数据库中获取数据。
这是我的 php 文件
<?php
$con = mysqli_connect("", "", "", "");
$username = $_POST["username"];
$password = $_POST["password"];
$statement = mysqli_prepare($con, "SELECT * FROM user WHERE username = ? AND password = ?");
mysqli_stmt_bind_param($statement, "ss", $username, $password);
mysqli_stmt_execute($statement);
mysqli_stmt_store_result($statement);
mysqli_stmt_bind_result($statement, $userID, $name, $age, $username, $password);
$response = array();
$response["success"] = false;
while(mysqli_stmt_fetch($statement)){
$response["success"] = true;
$response["name"] = $name;
$response["age"] = $age;
$response["username"] = $username;
$response["password"] = $password;
}
echo json_encode($response);?>
我无法弄清楚它有什么问题。我已经尝试了很多东西。
这是有错误的代码块
Response.Listener<String> responseListener = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonResponse = new JSONObject(response);
boolean success = jsonResponse.getBoolean("Success");
if (success) {
String name = jsonResponse.getString("name");
int age = jsonResponse.getInt("age");
【问题讨论】:
-
我认为这是错误的代码块。您是否正在尝试将响应转换为 json 对象?错误说例如
at org.json.JSONObject.getBoolean(JSONObject.java:410) -
json 区分大小写 ...
-
对不起。我对此很陌生。它不会在代码中显示任何错误。我读了很多帖子说我的 php 文件中可能有错误。