I have a JSONArray that needs to be inserted into a JTable, but from what I've googled I reached the conclusion that it's easier to insert a JSONArray into a JTable by converting it into a JSONObject and then I can insert it to the JTable using an ArrayList.
I've managed to convert the JSONArray to a JSONObject as shown below, but I'm stuck when I try to convert it into an Arraylist and then inserting it into the JTable. Can you tell me how to do it? Is there an easier way to insert the JSONArray into a JTable?
JSONArray:
[{"FOODID":"Jus Alpukat","PRICE":"7000","NUM":"1","RES":"7000.0","ORDERID_FK":""},{"FOODID":"Ice Cream","PRICE":"5000","NUM":"10","RES":"50000.0","ORDERID_FK":""}]
JSONObject:
{"RES":"7000.0","PRICE":"7000","NUM":"1","FOODID":"Jus Alpukat","ORDERID_FK":""}
{"RES":"50000.0","PRICE":"5000","NUM":"10","FOODID":"Ice Cream","ORDERID_FK":""}
JSONArray to JSONObject conversion program:
JSONArray jsonArr = new JSONArray(lineRead);
List<Data> dataList = new ArrayList<>();
for (int i = 0; i < jsonArr.length(); i++) {
JSONObject jsonObj = jsonArr.getJSONObject(i);
Data data = new Data();
data.foodid = jsonObj.getString("FOODID");
data.price = jsonObj.getString("PRICE");
data.num = jsonObj.getString("NUM");
data.res = jsonObj.getString("RES");
dataList.add(data);
}