1、首先引入alibaba的fastjson包
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.58</version>
</dependency>
2、方法罗列
public static Object strToMap(String str){
Object obj = JSONObject.parseObject(str, Object.class);
return obj;
}
public static Map objectToMap(Object obj){
Map map = JSONObject.parseObject(JSONObject.toJSONString(obj), Map.class);
return map;
}
public static String objectToStr(Object obj){
String str = JSONObject.toJSONString(obj);
return str;
}
public static List<Object> strToList(String str){
List<Object> objectList = JSONObject.parseArray(str, Object.class);
return objectList;
}
public static String listToStr(List<Object> list){
String str = JSONObject.toJSONString(list);
return str;
}