fastJson顺序遍历JSON字段
来源:互联网 发布:单词社交网络 微盘 编辑:程序博客网 时间:2024/03/29 18:59
fastJson在把json格式的字符串转换成JSONObject的时候,使用的是HashMap,所以排序规则是根据HASH值排序的,如果想要按照字符串顺序遍历JSON属性,需要在转换的时候指定使用LinkedHashMap代替HashMap。
public static void main(String[] args) { String jsonStr = "{\"size\":\"7.5\",\"width\":\"M (B)\"}"; System.out.println("无序遍历结果:"); JSONObject jsonObj = JSON.parseObject(jsonStr); for (Map.Entry<String, Object> entry : jsonObj.entrySet()) { System.out.println(entry.getKey() + ":" + entry.getValue()); } System.out.println("-------------------"); System.out.println("有序遍历结果:"); LinkedHashMap<String, String> jsonMap = JSON.parseObject(jsonStr, new TypeReference<LinkedHashMap<String, String>>() { }); for (Map.Entry<String, String> entry : jsonMap.entrySet()) { System.out.println(entry.getKey() + ":" + entry.getValue()); } }
0 0
- fastJson顺序遍历JSON字段
- fastJson顺序遍历JSON字段
- fastJson按照字符串顺序遍历JSON字段
- alibaba.fastjson指定json属性的顺序
- java alibaba fastJson 遍历数组json
- ALiBABa fastjson去除JSON对象不需要的属性字段
- Fastjson 实体类JSON化过滤字段操作-PropertyFilter
- ALiBABa fastjson去除JSON对象不需要的属性字段
- Json---fastJson
- Json-fastjson
- JS 遍历 json对象的顺序错乱
- fastjson过滤字段属性
- FastJson字段解析问题
- fastjson过滤指定字段
- fastjson过滤指定字段
- FastJson过滤字段
- FastJson过滤字段
- fastjson.toJSONString字段排序
- Objective-C 面向对象(类II)
- Python学习01
- openssl hmac 介绍
- splay树的实现
- The Factor
- fastJson顺序遍历JSON字段
- uva ---11136Hoax or what--优先队列即可
- [LinkerScript.8] 简单的链接器脚本命令: 杂项命令 - Simple Linker Script Commands : Miscellaneous Commands
- Java中实现对象的比较
- 89 文件压缩和解压缩
- 我们有自己的论坛啦!基于Discuz构建,还不来注册~
- Android PMem 和Ashmem 介绍
- SpringMVC——接收请求参数和页面传参
- jQuery 上传头像插件Jcrop的实例