当前位置:网站首页>秒懂JSONArray和JSONObject的区别和使用
秒懂JSONArray和JSONObject的区别和使用
2022-06-26 13:31:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
一.JSONObject是什么? 就是对象json; 之前在秒懂json中说过,{}表示对象, 所以JSONObject就是:{“name”:”tom”} 同时, 这里的对象Json通过添加数组json可以变成对象数组json: {“name”:[“tome”,”kate”]} 例如: JSONObject jsono = new JSONObject();
JSONArray jsona = new JSONArray();
jsona.put(“tom”);
jsona.put(“kate”);//[“tom”,”kate”]
jsono.put(“name”,jsona);//{“name”:[“tom”,”kate”]}
二.JSONArray是什么? 就是数组json 之前在秒懂json中说过,[]表示数组, 所以JSONArray就是[“tom”,”kate”,”jerry”];或者[1,2,3] 同时,这里的数组json通过添加对象json可以变成数组对象json: [{“name”:”tom”},{“name”:”kate”}] 例如: JSONArray jsona = new JSONArray();
JSONObject jsono1 = new JOSNObject();
JSONObject jsono2 = new JSONObject();
jsono1.put(“name”,”tom”);//{“name”:”tom”} jsono2.put(“name”,”kate”);//{“name”:”kate”}
jsona.put(json1,json2);//[{“name”:”tom”},{“name”:”tom”}]
三.两者结合还可以生成对象数组对象json:{“book”:[{“name”:”harrypotter”},{“name”:”potterharry”}]} ①创建对象json->jsono1:{“name”:”harrypotter”}:jsona1.put(“name”,”harrypotter”); ②创建对象json->jsono2:{“name”:”potterharry”}:jsona2.put(“name”,”potterharry”); ③创建数组json->jsona:[{“name”:”harrypotter”},{“name”:”potterharry”}]:jsona.put(jsona1);jsona.put(jsona2); ④创建对象json->jsono3:jsono3.put(“book”,jsona);
注:JSONArray和JSONObject再使用时候的第一个最重要的区别就是: JSONArray是一个一个加进去的; JSONObject是一对一对加进去的;
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/133818.html原文链接:https://javaforall.cn
边栏推荐
- C language ---getchar() and putchar()
- Sword finger offer 10 Ⅰ 10Ⅱ. 63 dynamic planning (simple)
- ArcGIS secondary development -- arcpy batch automatic map publishing service
- 近期比较重要消息
- C | analysis of malloc implementation
- CF676C Vasya and String
- Exercise set 1
- DOS command
- Related knowledge of libsvm support vector machine
- Common evaluation indexes of classification model -- confusion matrix and ROC curve
猜你喜欢

Generation and rendering of VTK cylinder

ThreadLocal巨坑!内存泄露只是小儿科...

Logical operation

9項規定6個嚴禁!教育部、應急管理部聯合印發《校外培訓機構消防安全管理九項規定》

Sword finger offer 18.22.25.52 Double pointer (simple)

Common controls and custom controls

BP neural network for prediction

Eigen(3):error: ‘Eigen’ has not been declared

程序员必备,一款让你提高工作效率N倍的神器uTools

C language | Consortium
随机推荐
Insect operator overloaded a fun
Zero basics of C language lesson 8: Functions
STM32F1和GD32F1有什么区别?
布局管理器~登录界面的搭建实例
Stream常用操作以及原理探索
GC is not used in D
DOS command
从Celsius到三箭:加密百亿巨头们的多米诺,史诗级流动性的枯竭
First k large XOR value problem
2021-10-18 character array
MySQL | basic commands
Niuke challenge 48 e speed instant forwarding (tree over tree)
7.consul service registration and discovery
Common controls and custom controls
Bug STL string
Cloudcompare - Poisson reconstruction
RISC-V 芯片架构新规范
Difference between classification and regression
array
C language ---getchar() and putchar()