Java 我想,在转换为json时,当我试图将数据发送到数据库时,我遇到了一个错误。如何将字符串转换为json

Java 我想,在转换为json时,当我试图将数据发送到数据库时,我遇到了一个错误。如何将字符串转换为json,java,android,sql,json,database,Java,Android,Sql,Json,Database,当我点击应用程序中的注册按钮时,我得到了这个信息 10-20 20:32:13.688 9146-9146/asylum.lotto.steed.codelotto W/System.err: org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject at org.json.JSON.typeMismatch(JSON.java:111) 10-20 20

当我点击应用程序中的注册按钮时,我得到了这个信息

10-20 20:32:13.688 9146-9146/asylum.lotto.steed.codelotto W/System.err: org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
    at org.json.JSON.typeMismatch(JSON.java:111)
10-20 20:32:13.689 9146-9146/asylum.lotto.steed.codelotto W/System.err:     at org.json.JSONObject.<init>(JSONObject.java:160)
    at org.json.JSONObject.<init>(JSONObject.java:173)
    at asylum.lotto.steed.codelotto.login.SignUpActivity$1$1.onResponse(SignUpActivity.java:51)
10-20 20:32:13.690 9146-9146/asylum.lotto.steed.codelotto W/System.err:     at asylum.lotto.steed.codelotto.login.SignUpActivity$1$1.onResponse(SignUpActivity.java:47)
    at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:60)
    at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30)
    at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
       at android.os.Handler.handleCallback(Handler.java:836)
     10-20 20:32:13.691 9146-9146/asylum.lotto.steed.codelotto W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:103)
    at android.os.Looper.loop(Looper.java:203)

10-20 20:32:13.688 9146-9146/shave.lotto.steed.codelotto W/System.err:org.json.JSONException:Value显然,当从服务器发送数据时,它会以html格式发送数据,除非添加头并创建数据数组。我没有在后端执行这些操作

哪一行引发异常?很可能您得到的字符串不是(有效的)JSON。因此,请看这一行,检查您试图转换为JSON的值。这表示这两行是错误的响应。Listener responseListener=new Response。Listener()JSONObject jsonResponse=new JSONObject(Response);对。那么,您是否已打印出(或以其他方式检查)响应的内容?那根绳子里是什么?
 register.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                final String name = regname.getText().toString();
                final String username = regusername.getText().toString();
                final String password = regpassword.getText().toString();

                Response.Listener<String> responseListeer = new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            JSONObject jsonResponse = new JSONObject(response);

                            boolean success = jsonResponse.getBoolean("success");

                            if(success){
                                Intent intent = new Intent(SignUpActivity.this, SigninActivity.class);
                                SignUpActivity.this.startActivity(intent);
                            }else{
                                AlertDialog.Builder builder = new AlertDialog.Builder(SignUpActivity.this);
                                builder.setMessage("Register Failed").setNegativeButton("Retry", null).create().show();
                            }

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                };


                RegisterRequest registerRequest = new RegisterRequest(name, username, password, responseListeer);
                RequestQueue queue = Volley.newRequestQueue(SignUpActivity.this);
                queue.add(registerRequest);
            }
        });
    }


}