I have a function which is returning Data as List in java class. Now as per my need, I have to convert it into Json Format.
Below is my fun
JSONObject responseDetailsJson = new JSONObject();
JSONArray jsonArray = new JSONArray();
List ls =new ArrayList();
for(product cj:cities.getList()) {
ls.add(cj);
JSONObject formDetailsJson = new JSONObject();
formDetailsJson.put("id", cj.id);
formDetailsJson.put("name", cj.name);
jsonArray.put(formDetailsJson);
}
responseDetailsJson.put("Cities", jsonArray);
return responseDetailsJson;