我需要将ArrayList<Map<String, String>>
对象转换为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
答案 0 :(得分:0)
您可以尝试使用Google的Gson库轻松将Java对象转换为Json,反之亦然
尝试以下代码
Gson gson = new Gson();
JsonArray jsonArray = gson.toJsonTree(dataList).getAsJsonArray();
编辑:将jsonArray转换为字符串
String jsonStr = gson.toJson(jsonArray); //This will convert JsonArray to Java string