对json进行排序处理

private String getSortJson(JSONObject json) {
Set<String> set = json.keySet();
List<String> list = new ArrayList<>();
list.addAll(set);
Collections.sort(list);
StringBuffer sb = new StringBuffer();
for (String key : list) {
sb.append(key).append("=").append(json.getString(key)).append("&");
}
sb.replace(sb.length() - 1, sb.length(), "");
return sb.toString();
}
posted @ 2018-11-26 10:44  松峰  阅读(3826)  评论(0编辑  收藏  举报