小任班长的博客 - map按key排序
type: channel
link: https://cnxiaocheng.top/tag/map按key排序/
items: gson将map 转成 josn字符串并按key进行排序

gson将map 转成 josn字符串并按key进行排序
type: item
date: 2019-08-12T09:00:00+08:00
description: 方法是将普通的map 转成LinkedHashMap，存放key这样就是key 的顺序 Map myMap = new LinkedHashMap(); myMap.put("device-uuid",Params.deviceUuid); myMap.put("slot-id",Params.slotId); myMap.put("quantity",Params.quantity); myMap.put("type",Params.type); myMap.put("ip",Params.ip); String myMapJsonStr = gson.toJson(myMap, LinkedHashMap.class);