import com.alibaba.fastjson.JSON; import java.util.List; import java.util.Map; public class JsonObjUtils { public static String obj2json(Object obj) throws Exception { return JSON.toJSONString(obj); } public static <T> T json2obj(String jsonStr, Class<T> clazz) throws Exception { return JSON.parseObject(jsonStr, clazz); } @SuppressWarnings("unchecked") public static <T> Map<String, Object> json2map(String jsonStr) throws Exception { return JSON.parseObject(jsonStr, Map.class); } public static <T> T map2obj(Map<?, ?> map, Class<T> clazz) throws Exception { return JSON.parseObject(JSON.toJSONString(map), clazz); } @SuppressWarnings("unchecked") public static <T> T map2obj(Map<String, Object> map, String paramName, Class<T> clazz) throws Exception { return JSON.parseObject(JSON.toJSONString( map.get(paramName)), clazz); } public static <T> List map2List(Map<String, Object> map, String paramName, Class<T> clazz)throws Exception { return JSON.parseArray(JSON.toJSONString( map.get(paramName)), clazz); } public static <T> T str2obj(String jsonStr, Class<T> clazz) throws Exception { return JSON.parseObject(jsonStr, clazz); } public static <T> List str2List(String jsonStr, Class<T> clazz)throws Exception { return JSON.parseArray(jsonStr, clazz); } }
最近下载更多
最近浏览更多
zhos0212 LV19
10小时前
467277 LV13
3月26日
studengaaa
3月17日
暂无贡献等级
a1325922140 LV1
2月19日
wbbhappy LV13
1月13日
LUN001
1月11日
暂无贡献等级
710581799
2023年12月21日
暂无贡献等级
2317696509 LV6
2023年12月15日
内心向阳 LV4
2023年11月8日
jjhhhh
2023年10月11日
暂无贡献等级