Chitra Nandpal
Chitra Nandpal

Reputation: 443

Multiple object request using Volley Android

I want to call API Using Volley. There is an Multiple object Request So i don't Know Proper way. I was tried to code as below.But it does not give me Response.So can Anyone help me???

MainActivity

public void  getJsonResponsePost(){

    JSONObject jsonData = new JSONObject();
    JSONObject json = new JSONObject();

    /*{"data":{"lang_type":"1","keyword":"","latitude":23.022499999999997,"longitude":72.57139833333333,"category":6}}*/
    try {
        jsonData.put("data",json);
        json.put("lang_type","1");
        json.put("keyword","");
        json.put("latitude",23.022499999999997);
        json.put("longitude",72.57139833333333);
        json.put("category",6);
        Log.d("TAG",jsonData.toString());
    } catch (JSONException e) {
        e.printStackTrace();
    }


    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url, json, new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response)
                {
                    Log.d("String Response :",response.toString());
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.d(" Error getting  :",error.toString());
        }
    });

    jsonObjectRequest.setTag(REQ_TAG);
    requestQueue.add(jsonObjectRequest);
}

I get the following response

String Response :: {"status":"0","message":"Please pass the language type."}

Upvotes: 0

Views: 383

Answers (1)

yahya.can
yahya.can

Reputation: 1810

Can you try this?

    try {
    json.put("lang_type","1");
    json.put("keyword","");
    json.put("latitude",23.022499999999997);
    json.put("longitude",72.57139833333333);
    json.put("category",6);
    jsonData.put("data",json);
    Log.d("TAG",jsonData.toString());
} catch (JSONException e) {
    e.printStackTrace();
}


JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url, jsonData, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response)
            {
                Log.d("String Response :",response.toString());
            }
        }, new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError error) {
        Log.d(" Error getting  :",error.toString());
    }
});

Upvotes: 1

Related Questions