当前位置:网站首页>Kotlin学习之json数据解析
Kotlin学习之json数据解析
2022-07-20 06:17:00 【Empereur。】
通过这篇文章,可以学习到
1. 如何根据json数据创建一个对应的数据类
2. 如何根据json数据创建一个对象
(一)根据json数据创建一个对应的数据类
data class Test(
val code : Int,
val message : String,
val warnMessage : String,
val data : List<Data>
)
data class Data(
val departmentCode : String,
val departmentName : String,
val dutyInfo : List<DutyInfo>
)
data class DutyInfo(
val doctorCode : String,
val doctorName : String,
val departmentCode : String,
val jobTitle : String,
val doctorProfile : String,
val restTicket : String,
val dutyDate : String,
val photo : String,
val duty : List<Duty>
)
data class Duty(
val dutyTimeName : String,
val dutyWeek : Int,
val totalTicket : Int,
val restTicket : Int,
val dutyDate : String
)
需要注意的是 在json中,如果数据是用 {}修饰,那么说明需要创建一个对象;如果是用【】修饰,那么需要创建一个数组列表
(二)如何根据json数据创建一个对象
如果是列表类型
//传入的json为列表类型
val json = "{\"code\":\"00001\",\"message\":\"test\",\"warnMessage\":\"test\"}"
val gson = Gson()
val account : Test = gson.fromJson(json,Test::class.java)
如果是数组类型
//传入的json为数组类型
val jsonArray = "[{\"zoneNumber\":\"00001\",\"roomNumber\":\"test\",\"bedNumber\":\"test\"}]"
val inf : List<InpatientInfo> = gson.fromJson(jsonArray, object : TypeToken<List<InpatientInfo>>(){
}.type)
------做个笔记-----
边栏推荐
- threeJS中dat.gui的使用显示文件夹点击时候及调色器
- DNA 7. 基因组拷贝数变异分析及可视化 (GISTIC2.0)
- 三地五中心(ldc(逻辑数据中心)单元化)和容灾
- Summary of relevant operations on deploying Drupal website on the server
- 深度解析字符串和内存函数
- The realization of Sanzi game
- DNA 8. Mutation heterogeneity of cancer and search for new cancer driver genes (mutsigcv)
- DNA 6. Genome variation: complexheatmap
- 可以快速提高编程能力的9个建议
- 超全干货:数据可视化的设计总结,工具,技术要点统统都有
猜你喜欢
一维卷积英语电影评论情感分类项目
If: the molecular composition of 14+ "smoking" myeloma highlights the evolutionary pathway leading to multiple myeloma
SCS [1] today starts a single-cell journey, describing the past and present lives of single-cell sequencing
阶跃数特征
Access数据库对象包括哪六个?Access与 Excel 最重要的区别是什么?
Step number characteristic
Redis的五种数据类型详解
通俗解释: IaaS,PaaS和SaaS的区别
threejst物体匀速移动
文末送书|豆瓣9.4分,“hello,world”起源于这本书!
随机推荐
Operation skills of markdown in jupyter
Flower of reverse analysis instruction 2
可以快速提高编程能力的9个建议
【MySQL】临时表 &视图
Solve tensoflow2 No module named:tensorflow contrib
Two dimensional convolution Chinese microblog emotion classification project
Excel中万能的查询函数——VLOOKUP(使用方法+实操)
Jupyternotebook plug-in management and installation
【Jailhouse 文章】Certify the Uncertified Towards Assessment of Virtualization for Mixed-criticality...
Testapi (node writes test interface without database, with basic data)
输入10个数, 使其所有的数向后移m个位置
编写一个Book类,该类至少有name和price两个属性。
threeJS中dat.gui的使用显示文件夹点击时候及调色器
文末送书|豆瓣9.4分,“hello,world”起源于这本书!
【FPGA教程案例32】通信案例2——基于FPGA的FSK调制信号产生
关于在服务器上部署Drupal网站的相关操作总结
EV代码签名证书可以自助续签吗?
c语言文件操作管理(下)
Principle and protection of DOM XSS
RNA 20. SCI 文章中单样本免疫浸润分析 (ssGSEA)