/**
* 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;
}
List 转成 Json
最新推荐文章于 2024-07-10 01:10:32 发布