当前位置:网站首页>Jsonobject is sorted in A-Z order of key
Jsonobject is sorted in A-Z order of key
2022-07-24 06:49:00 【cxcaln】
Recently, Tiktok has been connected api, Interface parameters need to be checked key Sort , Search the , I found that many articles adopt
JSONObject object2 = new JSONObject(true);This way, , Most of them adopt this method , It seems that they quarrel with each other , No verification , This is the wrong way . This initializes , It initializes an ordered JSON, Not sorted JSON, To put it bluntly , Will follow you put Sequential storage of .
Everybody knows ,java in map Sets are unordered , The set type we need to adopt is SortedMap, Here is the validation :
JSONObject object1 = new JSONObject();
JSONObject object2 = new JSONObject(true);
SortedMap map = new TreeMap();
object1.put("order",123);
object2.put("order",123);
map.put("order",123);
object1.put("name"," Zhang San ");
object2.put("name"," Li Si ");
map.put("name"," Wang Wu ");
object1.put("age",1);
object2.put("age",2);
map.put("age",2);
System.out.println(object1.toJSONString());
System.out.println(object2.toJSONString());
System.out.println(map.toString());Here I define three objects ,object1 It's ordinary. json,object2 Is ordered json,map Is the sort of json, Let's look at the output :

Obviously ,object1 Is chaotic ,object2 It is stored in the order of insertion , and map Is the real sorting .
There's another way , You can sort by yourself , Compare each key First of all ascll value , And then sort it , Then insert into an ordered json In the assembly , It can also be realized , Just more trouble .
You can check the information on the Internet , Be sure to verify it yourself
边栏推荐
- MGR_mysqlsh_keepalive高可用架构部署文档
- Special effects - click the mouse and the randomly set text will appear
- Redis基本类型-哈希Hash
- 在IDEA里斗个地主不过分吧!
- Special effects - when the mouse moves, stars appear to trail
- 【LVGL(2)】LVGL入门,在CodeBlock上进行模拟以及移植STM32
- Random forest, lgbm parameter adjustment based on Bayesian Optimization
- DNS domain name resolution service
- Take you to understand the inventory deduction principle of MySQL database
- JS - mouse and keyboard configuration and browser forbidden operation
猜你喜欢

NFS shared services and experiments

Special effects - click the mouse and the randomly set text will appear
![[lvgl (6)] display Chinese settings and make Chinese font](/img/a4/1b0d0b7a5789ecc8f9a2a8cd93d92e.png)
[lvgl (6)] display Chinese settings and make Chinese font

Special effects - bubble tailing occurs when the mouse moves

类的加载器 和 双亲委派机制详解

我有 7种 实现web实时消息推送的方案,7种!

Jenkins CI CD
![[lvgl (5)] label usage](/img/55/f25a510cf04caff7ee15e72360c3a1.png)
[lvgl (5)] label usage

神经网络超参数调整(基于ray包)

kubernetes 的Deployment(部署),Service概念,动态扩缩容
随机推荐
极客星球丨 字节跳动一站式数据治理解决方案及平台架构
Account and authority management
[lvgl (1)] a brief introduction to lvgl
随机森林、LGBM基于贝叶斯优化调参
Today, let's talk about the underlying architecture design of MySQL database. How much do you know?
Special effects - return to the top (kitten effects)
JS - calculate the side length and angle of a right triangle
磁盘管理和文件系统
深入了解MySQL 两把锁啥时候用(表锁,行锁)
JS - mouse and keyboard configuration and browser forbidden operation
分组后返回每组中的最后一条记录 GROUP_CONCAT用法
Sealos 打包部署 KubeSphere 容器平台
Write blog at leisure ~ briefly talk about let, VaR and Const
Directory and file management
带你深入了解MySQL数据库扣减库存原理
Promise (try to implement a promise by yourself) more detailed comments and other interfaces are not completed yet. Let's continue next time.
JS - numerical processing (rounding, rounding, random numbers, etc.)
The character that appears the most times in the JS output string
Jmeter分布式压测
Special effects - Cherry Blossom falling background effects