net.sf.json.JSONArray String list = JSONArray.fromObject(inputList).toString();
com.google.gson.Gson Gson gson = new Gson(); Map<String, Object> resultMap = new HashMap<String, Object>(); resultMap.put("total", total); resultMap.put("rows", inputList); String resultList = gson.toJson(resultMap).toString();
以上两种将集合list转换为String的方式结果都一样:[{"id":"123","name":"rr"},{},{}]