2017-05-04 21 views
-1

私は電子メールとパスワードでデータベースにログインし、その情報を取得します。私は私の問題が何であるか知っていません。なぜなら、サインインボタンをクリックすると、 何も表示されないからです。エラーは次のとおりです。java.lang.StringをJSONObject 2に変換できません

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

マイログインコード:

Button SignIn = (Button) findViewById(R.id.btn_signIn); 
final EditText etEmail = (EditText) findViewById(R.id.etMail); 
final EditText etPassword = (EditText) findViewById(R.id.etPassword); 

SignIn.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View v) { 
     email = etEmail.getText().toString(); 
     password = etPassword.getText().toString(); 

     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"); 
         String surname = jsonResponse.getString("surname"); 

         Intent intent = new Intent(LoginActivity.this, UsersMainActivity.class); 
         intent.putExtra("name", name); 

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

     }; 

     LoginRequest loginRequest = new LoginRequest(email, password, responseListener); 
     RequestQueue queue = Volley.newRequestQueue(LoginActivity.this); 
     queue.add(loginRequest); 
    } 
}); 

私のPHPコード:あなたの応答は、HTMLコードを与えているように思え

<?php 
$con = mysqli_connect("localhost","id1519330","****","id1519330"); 

    $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, $id, $name, $surname, $email, $password); 

    $response = array(); 
    $response["success"] = false; 

while(mysqli_stmt_fetch($statement)){ 

      $response["success"] = true; 
      $response["name"] = $name; 
      $response["surname"] = $surname; 
      $response["email"] = $email; 
      $response["password"] = $password; 

    } 
    echo json_encode($response); 
?> 
+0

ポップアップまたはコンソールprintlnを追加して、パスワードと電子メールが最初にjsonオブジェクトではなく文字列であることを確認してください。その後、実際の応答が何であるかを確認し、オブジェクト全体を印刷する必要があります。あなたはどこかで何かを間違って解析しています。エラーメッセージ自体は実際にあなたが間違って解析しているものを伝えるべきですが、全体を含めなかったのです – JordanGS

+0

あなたの画面の右側に '関連する'セクションがあります。同じ質問のトンが答えられました。 –

答えて

0

は(たまたまあなたのリクエストがステータス200を出さないときは、デバッガまたはプリンターを使用してStringレスポンスをチェックしてくださいあなたのリクエストに間違いがあるかどうかを知ることができます。

0

それはあなたがresponseは解析するjsonの正しいスタイルを持っていないことです。詳細については、this page を参照してください。response

関連する問題