构造函数中指定使用有序

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());

输出结果为:

fastjson字段顺序问题

元素顺序和put的顺序相同

相关文章: