fastjson字段顺序问题

构造函数中指定使用有序

public JSONObject(boolean ordered) {
this(16, ordered);
}

示例:
JSONObject fastJson = new JSONObject(true);
fastJson.put("1", "1");
fastJson.put("2", "1");
fastJson.put("3", "1");
fastJson.put("11", "1");
fastJson.put("22", "1");
fastJson.put("33", "1");
fastJson.put("111", "1");
fastJson.put("222", "1");
fastJson.put("333", "1");
 
 
System.out.println(fastJson.toJSONString());

输出结果为:

元素顺序和put的顺序相同

posted @ 2019-10-18 14:36  tc310  阅读(782)  评论(0编辑  收藏  举报