工具类
This commit is contained in:
@@ -9,6 +9,8 @@ import java.util.*;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
|
||||
import java.util.List;
|
||||
@@ -19,14 +21,43 @@ import java.util.stream.Stream;
|
||||
* @author lyf
|
||||
*/
|
||||
public class ListUtil {
|
||||
|
||||
private static ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
public static JSONArray stringChangeList(String listString){
|
||||
// 使用Fastjson将JSON字符串转换为JSONArray对象
|
||||
return JSON.parseArray(listString);
|
||||
|
||||
}
|
||||
|
||||
public static JSONObject stringToJSONObject(String str){
|
||||
return JSONObject.parseObject(str);
|
||||
}
|
||||
public static <T> T stringToJson(String json, Class<T> valueType) {
|
||||
try {
|
||||
return objectMapper.readValue(json, valueType);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public static String toString(Object json){
|
||||
try {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
return objectMapper.writeValueAsString(json);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> List<?> toList(String json,List<T> list){
|
||||
try {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
return objectMapper.readValue(json,list.getClass());
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String JSONArrayChangeString(JSONArray jsonArray){
|
||||
return jsonArray.toString();
|
||||
|
||||
Reference in New Issue
Block a user