//map2json
public static <K , V> String toJSON(Map<K, V> map){
if(null == map || map.isEmpty()){
return "";
}
JSONObject jsonObject = new JSONObject();
jsonObject.putAll(map);
return jsonObject.toString();
}
//json2map
@SuppressWarnings("unchecked")
public static <K, V> Map<K, V> toMap(String json){
if(StringUtils.isBlank(json)){
return Collections.emptyMap();
}
JSONObject jsonObject = JSONObject.fromObject(json);
return (Map<K, V>) JSONObject.toBean(jsonObject, HashMap.class);
}
JSON to MAP,MAP to JSON
最新推荐文章于 2024-02-06 10:24:34 发布