Reputation: 8952
Hello all i am using volley to send request to the server. I am sending some params to server & getting a json array & json object in response. As of now i am using JsonObjectRequest custom request for getting the response.If the response is JsonArray i get the json array if response is jsonObject then i get the json object.So which approach should i follow for getting the response?
Following is the code for sending request
public void sendData()
{
RequestQueue que=Volley.newRequestQueue(this);
Map<String, String> params = new HashMap<String, String>();
params.put("fname",fname );
params.put("lname",lname );
params.put("email",email );
params.put("pswd",password);
final ProgressDialog dialog = new ProgressDialog(HealthCreateAccount.this);
dialog.setTitle("Please Wait");
dialog.setMessage("Creating Account..");
dialog.setCancelable(false);
dialog.show();
CustomRequest jsObjRequest = new CustomRequest(Method.POST, url, params, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response)
{
dialog.dismiss();
Toast.makeText(getApplicationContext(), response.toString(), Toast.LENGTH_SHORT).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError response) {
dialog.dismiss();
Toast.makeText(getApplicationContext(), "Unable to Create Account!", Toast.LENGTH_SHORT).show();
Log.i("RAE",response.toString());
}
});
que.add(jsObjRequest);
}
Upvotes: 2
Views: 3138
Reputation: 599
Json Object & Json array is type request. Json object will try to fetch a json array where as json object will fetch json object.However you can use json object & create a json array in a json object.
Upvotes: 3