当前位置:网站首页>JSON data analysis of kotlin learning
JSON data analysis of kotlin learning
2022-07-21 05:00:00 【Empereur。】
Through this article , You can learn
1. How to base on json Data create a corresponding data class
2. How to base on json Data create an object
( One ) according to json Data create a corresponding data class
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
)
It should be noted that stay json in , If the data is used {} modification , Then it means that you need to create an object ; If it is to use 【】 modification , Then you need to create an array list
( Two ) How to base on json Data create an object
If it's a list type
// Incoming json Is a list type
val json = "{\"code\":\"00001\",\"message\":\"test\",\"warnMessage\":\"test\"}"
val gson = Gson()
val account : Test = gson.fromJson(json,Test::class.java)
If it's an array type
// Incoming json Is an array type
val jsonArray = "[{\"zoneNumber\":\"00001\",\"roomNumber\":\"test\",\"bedNumber\":\"test\"}]"
val inf : List<InpatientInfo> = gson.fromJson(jsonArray, object : TypeToken<List<InpatientInfo>>(){
}.type)
------ Take a note -----
边栏推荐
- Principle and protection of DOM XSS
- 掌握这些插件,分分钟提高你的办公效率90%!
- Keil编译下载报错:No Algorithm found for: 08000000H - 08001233H解决办法
- Access数据库对象包括哪六个?Access与 Excel 最重要的区别是什么?
- Excel中实用的3个数据透视表操作技巧,简单高效!
- 【组队 PK 赛】积分商城已开启 | 即刻兑换专属好礼
- 一文看懂:零代码、0代码、无代码平台是什么?怎么选?
- FigDraw 12. Correlation matrix of SCI article drawing
- RNA 23. Risk factor association diagram of Cox model of expressed genes in SCI articles (ggrisk)
- 2022年软件测试最新面试题及解析
猜你喜欢
为什么说CRM对于企业来说非常重要?看完值得思考
Threejst objects move at a constant speed
MySQL数据库并发,上锁的问题(共享锁和排它锁)
与传统IT开发相比,低代码平台有何优势?
Three practical PivotTable operating skills in Excel, simple and efficient!
DNA 9. Uncover the correlation between tumor heterogeneity and TMB, MSI
基于STM32设计的动态密码锁
SaaS最通俗易懂的解释是什么?看这篇就够了
VAE图片生成实战
Kotlin学习之json数据解析
随机推荐
Programming and Philosophy (1)
Can ev code signing certificates be self renewed?
[FPGA tutorial case 32] communication case 2 - FSK modulation signal generation based on FPGA
输入10个数, 使其所有的数向后移m个位置
this的指向
With great power there must come great responsibility.
Testapi (node writes test interface without database, with basic data)
与传统IT开发相比,低代码平台有何优势?
掌握这些插件,分分钟提高你的办公效率90%!
为什么说CRM对于企业来说非常重要?看完值得思考
Hyperchain超块链史兴国接受36氪采访:客户合作咨询量都在翻倍
What is the easiest explanation for SaaS? Just read this one
阶跃数特征
如果在加密领域有段位,你是“青铜”还是“王者”?
c语言文件操作管理(下)
Router link opens a new page Jump and a tag to prevent default jump and various attributes
VAE图片生成实战
One dimensional convolution English film review emotion classification project
If: the molecular composition of 14+ "smoking" myeloma highlights the evolutionary pathway leading to multiple myeloma
threeJS中dat.gui的使用显示文件夹点击时候及调色器