I'm trying to build an array of objects, something like this
[
{ name: "joe", id: "123"},
{ name: "ken", id: "234"},
{ name: "dave", id: "987"}
]
End goal is to return this as a JSON object in API response. I'd like to use JSON.simple, Greatly appreciate any suggestions,
I am sure there is better way to code, below is what I have currently,
am sure there is better way to code, below is what I have currently,
JSONObject obj1 = new JSONObject();
obj1.put("id", "123");
obj1.put("name", "joe");
JSONObject obj2 = new JSONObject();
obj2.put("id", "234");
obj2.put("name", "ken");
JSONObject obj3 = new JSONObject();
obj3.put("id", "987");
obj3.put("name", "dave");
JSONArray list = new JSONArray();
list.add(obj1);
list.add(obj2);
list.add(obj3);