fastjson 序列化,反序列化Map对象的顺序问题

使用JSONObject  读取JSON字符串时,读取出来的数据,通过变量时是无序的。

但是业务希望返回是顺序的。

String str="{name:"A",address:"B",tel:"C",user:{name:"A",address:"B"}}";
JSONObject json=JSONObject.parseObject(str);

解决办法如下:

LinkedHashMap<String, Object> map= JSON.parseObject(str,new TypeReference<LinkedHashMap<String, Object>>(){}, Feature.OrderedField);

使用如上代码,这样map 返回都数据就是按照 json 的原来顺序进行输出。

原文地址:https://www.cnblogs.com/yg_zhang/p/10704382.html