I have to access a web service which takes one parameter and gives JSONArray in response. I want to know how to send a POST parameter so that I get response in JSONArray.
So far I have done the JSON Parsing part correctly and the data is being populated in recycler view. I have tried to Override protected Map<String, String> getParams()
as seen in one tutorial but that override is showing an error "Method does not override method from its superclass"
. Kindly see my code and guide me on how to implement it correctly.
public void JSON_WEB_CALL(){
JsonArrayRequest jsArrRequest = new JsonArrayRequest
(Request.Method.GET, HTTP_SERVER_URL, null, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
//mTxtDisplay.setText("Response: " + response.toString());
JSON_PARSE_DATA_AFTER_WEBCALL(response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// TODO Auto-generated method stub
}
@Override //This Override is showing an error "Method does not override method from its superclass"
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("param1", "one");
params.put("param2", "two");
return params;
}
});
requestQueue = Volley.newRequestQueue(this);
requestQueue.add(jsArrRequest);
}
public void JSON_PARSE_DATA_AFTER_WEBCALL(JSONArray array){
for(int i = 0; i<array.length(); i++) {
DataModel GetDataModel = new DataModel();
JSONObject json = null;
try {
json = array.getJSONObject(i);
GetDataModel.setId(json.getString("PRODID"));
GetDataModel.setPlateNo(json.getString("GRADE"));
GetDataModel.setPlateCode(json.getString("COLOR"));
}
catch (JSONException e)
{
e.printStackTrace();
}
DataAdapterClassList.add(GetDataModel);
mSwipeRefreshLayout.setRefreshing(false);
}
recyclerViewadapter = new NewRecyclerViewAdapter(DataAdapterClassList, this);
recyclerView.setAdapter(recyclerViewadapter);
if (array.length()!=0) {
SHOW_ALERT(array);
sendNotification(recyclerView, array);
}
}