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;
}
}