I want to create a JSONObject like this:
[
{
id:01,
name:"John",
number:010
},
{
id:02,
name:"Mike",
number: 020
}
]
This is my code:
public void equipmentViewed(List<Equipment> equipmentSelected, final OnControlResponseListener listener, String description, Equipment equipment) throws JSONException {
wsAccessControl = WSAccessControl.getInstance();
EquipmentViewed equipmentViewed = new EquipmentViewed();
equipmentViewed.setEquipment(equipmentsCount(equipmentSelected));
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("", new JSONArray(equipmentViewed.getEquipment().toString()));
} catch (JSONException e) {
Log.e(TAG, "Failed to create json object. Cause: " + e.getMessage());
}
String url = Constants.PROVIDER_DOMAIN_URL + Constants.REQUEST_EQUIPMENT;
wsAccessControl.makeWSRequest(RequestType.POST, url, jsonObject, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
listener.OnResponseReceived(response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
listener.OnResponseError(error);
}
}, true);
}
Where EquipmentViewed contains a String list equipment.
equipmentViewed.getEquipment()? please share