将lang.string转换为JSONObject

时间:2018-09-06 13:14:20

标签: java android json

我正在尝试为一个android应用程序创建一个注册页面。我看了一些有关它的教程。在该教程中,程序员编写了这段代码并且对他有用。现在的问题是它在我的代码上抛出了JSONException。这是代码。

  Response.Listener<String> responseListener = new Response.Listener<String> 
  () {
                @Override
                public void onResponse(String response) {
                //this is the response from register.php
                    try {
                        Log.d("RESPONSE",response);
                        JSONObject jsonResponse = new JSONObject(response);
                        boolean success = jsonResponse.getBoolean("success");
                        if(success){
                            Intent intent0 = new Intent(RegisterActivity.this,LoginActivity.class);
                            RegisterActivity.this.startActivity(intent0);
                        }
                        else{
                            AlertDialog.Builder builder = new AlertDialog.Builder(RegisterActivity.this);
                            builder.setMessage("Register Failed")
                                    .setNegativeButton("Retry",null)
                                    .create()
                                    .show();

                        }


                    } catch (JSONException e) {
                        e.printStackTrace();
                        Toast.makeText(RegisterActivity.this, "its here", Toast.LENGTH_LONG).show();
                    }
                }
            };

当我按一下REGISTER按钮时,它会显示一个Toast(在接发部分中) 并抛出 json.JSONException:值

这是Log.d(“ RESPONSE”,response);结果


                                                                     警告:mysqli_prepare()期望参数1为mysqli,在 19 行的 /home2/amirrez2/public_html/register.php 中给定的null br />                                                                      
                                                                     警告:mysqli_stmt_bind_param()期望参数1为mysqli_stmt,在 /home2/amirrez2/public_html/register.php 第20行 < br />                                                                      
                                                                     警告:mysqli_stmt_execute()期望参数1为mysqli_stmt,在 21 行的 /home2/amirrez2/public_html/register.php 中给定的null br />                                                                      
                                                                     警告:mysqli_stmt_store_result()期望参数1为mysqli_stmt,在 22 <行上的 /home2/amirrez2/public_html/register.php 中给定的null br />                                                                      
                                                                     警告:mysqli_stmt_num_rows()期望参数1为mysqli_stmt,在 23 /home2/amirrez2/public_html/register.php 中给出的null br />                                                                      
                                                                     警告:mysqli_stmt_close()希望参数1为mysqli_stmt,在 24 行的 /home2/amirrez2/public_html/register.php 中给定的null br />                                                                      
                                                                     警告:mysqli_prepare()期望参数1为mysqli,在 12 /home2/amirrez2/public_html/register.php 中给出的null br />                                                                      
                                                                     警告:mysqli_stmt_bind_param()期望参数1为mysqli_stmt,在 13 /home2/amirrez2/public_html/register.php 中给定的null br />                                                                      
                                                                     警告:mysqli_stmt_execute()期望参数1为mysqli_stmt,在 14 /home2/amirrez2/public_html/register.php 中给出的null br />                                                                      
                                                                     警告:mysqli_stmt_close()期望参数1为mysqli_stmt,在 15 /home2/amirrez2/public_html/register.php 中给出的null br />                                                                      {“成功”:true}

谢谢。

0 个答案:

没有答案