当前位置:网站首页>秒懂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
边栏推荐
- 9 regulations and 6 prohibitions! The Ministry of education and the emergency management department jointly issued the nine provisions on fire safety management of off campus training institutions
- 虫子 STL string上
- Memory considerations under bug memory management
- Never use redis expired monitoring to implement scheduled tasks!
- 程序员必备,一款让你提高工作效率N倍的神器uTools
- Caelus - full scene offline mixed Department solution
- 爱可可AI前沿推介(6.26)
- Research on balloon problem
- Pointer
- Win10 home vs pro vs enterprise vs enterprise LTSC
猜你喜欢

Exercise set 1

Sword finger offer 45.61 Sort (simple)

Freefilesync folder comparison and synchronization software

Pycharm远程连接服务器来跑代码

量化框架backtrader之一文读懂observer观测器

RISC-V 芯片架构新规范

Pychar remotely connects to the server to run code

C language | Consortium

BP neural network for prediction

Intellij IDEA--格式化SQL文件的方法
随机推荐
d检查类型是指针
Exercise set 1
从Celsius到三箭:加密百亿巨头们的多米诺,史诗级流动性的枯竭
Bug STL string
Research on balloon problem
Formal parameters vs actual parameters
Free machine learning dataset website (6300+ dataset)
Bug memory management
C language ---getchar() and putchar()
Sword finger offer 06.24.35 Linked list
Is it safe to open a securities account? Is there any danger
SwiftUI找回丢失的列表视图(List)动画
[jsoi2015] string tree
Common controls and custom controls
ArcGIS secondary development - arcpy delete layer
Luogu p4513 xiaobaiguang Park
How to call self written functions in MATLAB
Original code, inverse code and complement code
Freefilesync folder comparison and synchronization software
Self created notes (unique in the whole network, continuously updated)