JSON to MAP,MAP to JSON

来源:互联网 发布:网络带给我们的利与弊 编辑:程序博客网 时间:2024/05/07 21:35
//map2jsonpublic 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);}

原创粉丝点击