W / System.err:org.json.JSONException:值<br of =“” type =“” java.lang.string =“” not =“” be =“” Convert =“” to =“” jsonobject =“ “ error =”“ how =”“ is =”“ can =”“ be =”“ fixed =”“

时间:2019-05-25 15:15:06

标签: java android response

=”“

我m遵循this视频中的步骤。

我正在:

  

W / System.err:org.json.JSONException:值

这是我的JAVA代码:

public void onResponse(String response) {
                        try {
                            JSONObject jsonResponse = new JSONObject(response);
                            boolean success = jsonResponse.getBoolean("success");
                            if (success){
                                String first_name = jsonResponse.getString("first_name");
                                String last_name = jsonResponse.getString("last_name");

                                Intent intent = new Intent(LoginActivity.this, HomePageActivity.class);
                                intent.putExtra("first_name", first_name);
                                intent.putExtra("last_name", last_name);

                            }else {
                                AlertDialog.Builder builder= new AlertDialog.Builder(LoginActivity.this);
                                builder.setMessage("Login Failed")
                                        .setNegativeButton("Retry", null)
                                        .create()
                                        .show();
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                    }

我的PHP代码:

<?php

    $con = mysqli_connect("*****", "********", "********", "*********");


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


	$statement = mysqli_prepare($con, "SELECT * FROM user WHERE email = ? AND password = ?");

	mysqli_stmt_bind_param($statement, "ss", $email, $password);
	mysqli_stmt_execute($statement);


    
    mysqli_stmt_store_result($statement);
	mysqli_stmt_bind_result($statement, $userid, $first_name, $last_name, $email, $password);


	$response = array();
	$response["success"] = false;
	
	while(mysqli_stmt_fetch($statement)){

        $response["success"] = true;

        $response["first_name"] = $first_name;

        $response["last_name"] = $last_name;

        $response["email"] = $email;

        $response["password"] = $password;

    }
    
    
	echo json_encode($response);

?>

上面问题中的调试错误 这是Debug:

  在

  com.thecreds.credsapp.LoginActivity $ 2 $ 1.onResponse(LoginActivity.java:47)           在com.thecreds.credsapp.LoginActivity $ 2 $ 1.onResponse(LoginActivity.java:43)

而且,仍然不知道我哪里出了错,我按照这些步骤操作了,但是它不起作用。

0 个答案:

没有答案