首页 > Web开发 > 详细

Map 转成Json字符串

时间:2019-08-28 15:47:09      阅读:88      评论:0      收藏:0      [点我收藏+]
public class MapUtil {
// map 转成json字符串

public static String mapToJsonStr(Map map){
Gson gson = new GsonBuilder().enableComplexMapKeySerialization().create();
return gson.toJson(map);
}

// map 转成 key=value & key2=value2形式
public static String mapToParam(Map<String, Object> map) {
if (map == null) {
return "";
}
StringBuffer sb = new StringBuffer();
for (Map.Entry<String, Object> entry : map.entrySet()) {
sb.append(entry.getKey() + "=" + entry.getValue());
sb.append("&");
}
String s = sb.toString();
if (s.endsWith("&")) {
s = org.apache.commons.lang.StringUtils.substringBeforeLast(s, "&");
}
return s;
}

}

Map 转成Json字符串

原文:https://www.cnblogs.com/bt2882/p/11424248.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!