I need to create a JSON Object for an Arraylist. Below is the code
public boolean submitOrder(ArrayList orderList) {
serUri
Look at this I'm trying to use GSON lib, try out this, I'm not tested. This should work fine.
From Json string to Json object this way:
String jsonStr = "{\"a\": \"A\"}";
Gson gson = new Gson();
JsonElement element = gson.fromJson (jsonStr, JsonElement.class);
JsonObject jsonObj = element.getAsJsonObject();
For your code this should work fine:
public boolean submitOrder(ArrayList orderList)
{
serUri = "lists.json";
method = "post";
Gson gson = new Gson();
String jsonstr = new Gson().toJson(orderList);
JsonElement element = gson.fromJson (jsonStr, JsonElement.class);
JsonObject jsonObject = element.getAsJsonObject();
WebServiceAsyncTask webServiceTask = new WebServiceAsyncTask();
webServiceTask.execute(serUri, method,jsonObject, this);
return true;
}