Reputation: 545
i need to convert my ArrayList<Map<String, String>>
object to the JSONArray
ArrayList<Map<String, String>> dataList = new ArrayList<Map<String, String>>();
//I tried this
JSONArray jsonArray = new JSONArray(dataList);
// I am importing (java-json.jar) for converting ArrayList to JSONArray
// But i can't put this array in to JqGrid in my jsp page it's does not give me any output
Upvotes: 1
Views: 2921
Reputation: 3820
You can try Google's Gson library for easy conversion of Java objects to Json and vice versa
Try below code
Gson gson = new Gson();
JsonArray jsonArray = gson.toJsonTree(dataList).getAsJsonArray();
EDIT : Convert jsonArray to string
String jsonStr = gson.toJson(jsonArray); //This will convert JsonArray to Java string
Upvotes: 2