jsonandroid-volleyjsonresponsejson-arrayagg

I have a problem to use Volley. want to use POST method with some parameters and get Array type response but my response is not array type


I have a problem using Volley. want to use POST method with some parameters and get Array type response but my response is not an array type. Here, I share my request code and response.

RequestQueue queue = Volley.newRequestQueue(this);
        StringRequest postRequest = new StringRequest(Request.Method.POST, "https://umrahtech.com/umrahtechapi.php",
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        // response
                        Log.d("Response", response);
                        route = null;
                        route_spinner.setSelection(0);
                        check_in_date = null;
                        check_out_date = null;
                        adults = child = room = child1 = child2 = child3 = child4 = child5 = 0;
                        text_adults.setText("0 Adult");
                        text_child.setText("0 Child");
                        text_room.setText("0 Room");
                        layout_child.setVisibility(View.GONE);
                        in_date.setText("Add Date");
                        out_date.setText("Add Date");
                    }
                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        // error
                        Log.d("Error.Response", error.toString());
                    }
                }) {
            @Override
            protected Map<String, String> getParams() {
                Map<String, String>  params = new HashMap<String, String>();
                params.put("case", "hotel_makkah");
                params.put("location", route);
                params.put("check_in_1", check_in_date);
                params.put("check_out_1", check_out_date);
                params.put("passengers", room_array.toString());
                return params;
            }
        };
        queue.add(postRequest);

Solution

  • I have solved this question in this way. Where hudx_Object and hudx_JSON is JSONObject

    RequestQueue queue = Volley.newRequestQueue(this);
        StringRequest hudxconnect = new StringRequest(Request.Method.POST, "https://umrahtech.com/umrahtechapi.php",
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            hudx_Object = new JSONObject(response);
                            if (hudx_Object != null) {
                                hudx_JSON = hudx_Object.getJSONObject("response");
                                hudx_Object = new JSONObject(hudx_JSON.toString());
                            } else {
                                hudx_Object = null;
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        // error
                        Log.d("Error.Response", error.toString());
                        progressDialog.dismiss();
                    }
                }) {
            @Override
            protected Map<String, String> getParams() {
                Map<String, String>  params = new HashMap<String, String>();
                params.put("case", "hotel_makkah");
                params.put("location", route);
                params.put("check_in_1", check_in_date);
                params.put("check_out_1", check_out_date);
                params.put("passengers", room_array.toString());
                return params;
            }
        };