How to create json format java

Home / Uncategorized / How to create json format java

I would like to create JSON format and I have some problem about this

I have no idea to create Jsonarray and JsonObject in JsonObject
"users": [7, 16, 35],
"group_id": "sdkfjsdkljflds"
I try

JSONObject jsonParams = new JSONObject();
try {
jsonParams.put("group_id", "dlfsdds");
jsonParams.put("users", list);

} catch (JSONException e) {
and my log is show
"users":"[7, 16, 35]",
ps. list is from
for (int k=0;k Answer:
You need to convert the list to JSONArray first:try {
jsonParams.put("group_id", "dlfsdds");

JSONArray listJson = new JSONArray();

for(int i=0; iRead more

Leave a Reply

Your email address will not be published. Required fields are marked *