Cómo enviar el valor de params como json array

Tengo que pasar el valor de los parameters de request para la API de suscripción y el valor debe pasar en este documento. ya que recibo un error de volley 400. ¿Alguien puede ayudarme a resolverlo?

Json

{ "number":"12345678", "password":"12345678", "first_name":"abc", "last_name":"xyz", "email":"abc@gmail.com" } 

también debe pasar el tipo de contenido y la authentication en el encabezado

 fun signup(requestp:String,number: String, password: String, firstname: String,lastname: String,email: String) { showDialog() var strReq: StringRequest val urlapireq= APIReqParam() val urlresult = URLCollection() var st:Boolean pDialog.setMessage("Signing...") showDialog() strReq= object : StringRequest(Request.Method.POST, URLCollection.obj.BASE_URL,object : Response.Listener<String> { override fun onResponse(response: String) { println("Change Password Response" + response.toString()) hideDialog() try { val responseObj = JSONObject(response) // Parsing json object response // response will be a json object val status = responseObj.getString(urlapireq.STATUS) val message = responseObj.getString(urlapireq.MESSAGE) val success = responseObj.getString(urlapireq.SUCCESS) val error = responseObj.getString(urlapireq.ERROR) val responsecode = responseObj.getString(urlapireq.RESPONSECODE) if (responsecode == "200") { Toast.makeText(applicationContext,success,Toast.LENGTH_SHORT).show() } else { Toast.makeText(applicationContext, error, Toast.LENGTH_LONG).show() } } catch (e: JSONException) { println("Request for SMS error : " + e.message) /*Boast.makeText(getApplicationContext(), "Request for SMS error : " + e.getMessage(), Toast.LENGTH_LONG).show();*/ } } }, object : Response.ErrorListener { override fun onErrorResponse(error: VolleyError) { System.out.println("Change Password: " + error.message) /*Boast.makeText(getApplicationContext(),"Registration Error: "+ error.getMessage(), Toast.LENGTH_LONG).show();*/ } }) { override fun getParams(): Map<String, String> { //Creating HashMap val params = HashMap<String, String>() params.put(urlapireq.REQUEST, "signup") params.put(urlapireq.Number, number) params.put(urlapireq.Password , password) params.put(urlapireq.FIRSTNAME , firstname) params.put(urlapireq.LASTNAME , lastname) params.put(urlapireq.EMAIL , email) return params } @Throws(AuthFailureError::class) override fun getHeaders(): Map<String, String> { val headers = HashMap<String, String>() headers.put("Content-Type", "application/json") return headers } } println("Verification Url : " + strReq!!) // val crashinst=CrashApplicationClass() CrashApplicationClass.instance?.addToRequestQueue(strReq,TAG) } 

pero como me da error de

BasicNetwork.performRequest: código de respuesta inesperado 400.

revisa este código como reference y hazlo de acuerdo con tu código.

 private void registerUser(){ final String username = editTextUsername.getText().toString().trim(); final String password = editTextPassword.getText().toString().trim(); final String email = editTextEmail.getText().toString().trim(); StringRequest stringRequest = new StringRequest(Request.Method.POST, REGISTER_URL, new Response.Listener<String>() { @Override public void onResponse(String response) { Toast.makeText(MainActivity.this,response,Toast.LENGTH_LONG).show(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Toast.makeText(MainActivity.this,error.toString(),Toast.LENGTH_LONG).show(); } }){ @Override protected Map<String,String> getParams(){ Map<String,String> params = new HashMap<String, String>(); params.put(KEY_USERNAME,username); params.put(KEY_PASSWORD,password); params.put(KEY_EMAIL, email); return params; } }; RequestQueue requestQueue = Volley.newRequestQueue(this); requestQueue.add(stringRequest); } 

intente utilizar la request de Json en lugar de utilizar la request de cadena

 JsonObjectRequest jsObjRequest = new JsonObjectRequest (Request.Method.POST, url, null, new Response.Listener<JSONObject({ @Override public void onResponse(JSONObject response) { mTxtDisplay.setText("Response: " + response.toString()); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { // TODO Auto-generated method stub } });