当前位置:网站首页>JSONObject遍历的时候顺序不一致,导致数据对应出错
JSONObject遍历的时候顺序不一致,导致数据对应出错
2022-08-09 07:01:00 【吃素的哈士奇】
JSONObject的数据顺序不对
为什么拿出来不对!
JSON的顺序是按照输出是按key的 Hashmap 来排序的,
而Hashmap 是无序的,所以取值的时候,就是随意顺序取
所需jar包
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.76</version>
</dependency>
怎么解决
给JSONObject转化的时候加上Feature.OrderedField。
JSONObject jsonObj = JSONObject.parseObject(ret,Feature.OrderedField);
具体代码
JSONObject jsonObj = JSONObject.parseObject(ret,Feature.OrderedField);
JSONObject jsonObj1 = jsonObj;
JSONArray jsonArray = null;
for (int i = 0; i < split.length; i++) {
if(i< (split.length-1)){
jsonObj1 = JSONObject.parseObject(jsonObj1.get(split[i]).toString());
}else {
try {
jsonArray = (JSONArray) jsonObj1.get(split[i].toString());
}catch (Exception e){
jsonArray = JSONArray.parseArray(jsonObj1.get(split[i]).toString());
}
}
}
项目部署中遇到得问题
记住版本尽量用我给得这个1.2.76 ,千万别用1.2.78.有可能会报错!!!
边栏推荐
猜你喜欢

Tkinter可以选择的颜色

灵活好用的sql monitoring 脚本 part7

The water problem of leetcode

Flask failed to create database without error

Inception V3 闭眼检测

无重复的字符的最长子串

找不到和chrome浏览器版本不同的chromedriver的解决方法

Error jinja2.exceptions.UndefinedError: 'form' is undefined

Altium designer software commonly used the most complete package library, including schematic library, PCB library and 3D model library

leetcode 之 零移位
随机推荐
错误:为 repo ‘oracle_linux_repo‘ 下载元数据失败 : Cannot download repomd.xml: Cannot download repodata/repomd.
SAP ALV 数据导出被截断的bug
io.lettuce.core。RedisCommandTimeoutException命令超时
The AD in the library of library file suffix. Intlib. Schlib. Pcblib difference
bzoj 5333 [Sdoi2018]荣誉称号
用tensorflow.keras模块化搭建神经网络模型
【Docker】Docker安装MySQL
ByteDance Interview Questions: Mirror Binary Tree 2020
Integer 线程安全的
虚拟机网卡报错:Bringing up interface eth0: Error: No suitable device found: no device found for connection
The JVM thread state
金九银十即将到来,求职套路多,面试指南我来分享~
【Oracle 11g】Redhat 6.5 安装 Oracle11g
shardingsphere data sharding configuration item description and example
物理层课后作业
Altium designer software commonly used the most complete package library, including schematic library, PCB library and 3D model library
MUV LUV EXTRA 2019CCPC秦皇岛站J题 KMP
(本章节完结)排序第五节——非比较排序(计数排序+基数排序+桶排序)(附有自己的视频讲解)
更改Jupyter Notebook默认打开目录
分布式id 生成器实现