List 转成 Json

来源:互联网 发布:有哪些好的数据库应用 编辑:程序博客网 时间:2024/05/17 08:50
/** * list转成json * @param list * @return */public static String listToJson(List<?> list) {// StringBuilder json = new StringBuilder();// String jsonStr = "{\"data\":\"";String tempStr = null;try {JSONArray json;json = JSONArray.fromObject(list);// String tempStr = null;tempStr = json.toString().replace('{', '[');tempStr = tempStr.replace('}', ']');tempStr = tempStr.replaceAll("\\s*['\"]?\\w+['\"]?\\:\\s*", "");// jsonStr += tempStr;// jsonStr += "\",\"success\":true}";} catch (Exception ex) {ex.printStackTrace();}return tempStr;}


原创粉丝点击