Hi i am trying to POST some data to PhP server and receive Json respond. But I still don't know how to POST different data type (ex String and int). Here is my code. Any help is much appreciate. Thanks (My staffID is String type, my beaconMajor and BeaconMinor are int type)
private void getEventRespondTest (RequestQueue requestQueue) {
//Creating a string request
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST,Config.DATA_URL,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject respond) {
try {
eventArray = new JSONArray();
eventDetail = new ArrayList<>();
eventArray = respond.getJSONArray("result");
eventDetail = getEventDetail(eventArray);
} catch (JSONException e) {
e.printStackTrace();
}
// }
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(Beacon_MainActivity.this, "Unable to fetch data: " +error.getMessage(),Toast.LENGTH_LONG).show();
}
}
) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> map = new HashMap<>();
map.put(Config.STAFF_ID, staffID);
map.put(Config.BEACON_MAJOR,beaconMajor);
map.put(Config.BEACON_MINOR,beaconMinor);
return map;
}
};
//Adding request to the queue
requestQueue.add(jsonObjectRequest);
}
private ArrayList getEventDetail(JSONArray j) {
ArrayList event = new ArrayList();
//Traversing through all the items in the json array
for (int i = 0; i < j.length(); i++) {
try {
//Getting json object
JSONObject json = j.getJSONObject(i);
//Adding the name of the event to array list
event.add(json.getString(Config.EVENT_TITLE));
} catch (JSONException e) {
e.printStackTrace();
}
}
spinner.setAdapter(new ArrayAdapter<String>(Beacon_MainActivity.this, android.R.layout.simple_spinner_dropdown_item, event));
return event;
}