当前位置:网站首页>Parse JSON format data and save it to entity class
Parse JSON format data and save it to entity class
2022-06-25 12:42:00 【fortunate_ leixin】
josn The data format is as follows , I need to get text And save it to the corresponding field of the entity class and store it in the warehouse .
Change array to object first , And then josnobject To string, Calling getString() Get value 
First step : Take out value The value in , At this time, it is still an array structure 
The second step : call JSONArray.parseArray(), take json Format data into array format , This allows you to use array related methods .
We call get Method , Then it becomes object Data of type , then object Type of data to string type , That is to call tostring Method 

The third step : Then it becomes json Formatted data 
Step four : Use JSONObject.parseObject Method , Yes, it will string Translate into corresponding JSONObject object , among string yes “ Key value pair ” Formal json character string , Turn into JSONObject Object can then use its built-in methods , Such as calling getString Method 

Step five : Calling getString Method , What's coming in is key, If removed text Value 

Finally, save the result of this parsing to the corresponding field of the entity class 
Or traversal , The specific implementation is as follows :
String lableValue = formLable.getValue();
JSONArray jsonArray = new JSONArray(lableValue);
for (int i=0;i<jsonArray.size();i++){
// Here is to take it out text Value , And I know text Below is 2, But you can't write dead , Therefore, when taking values, you can directly jsonArray.size()-1 , Take this value . It's fine too jsonArray.get(i), In this way, it can also ensure that the last subscript represents key Namely text, Call again toString Method gets value
formBusinessTravelApply.setDeptName(jsonArray.getJSONObject(jsonArray.size()-1).get("text").toString());
}
Understand the wrong , Welcome to correct ~
边栏推荐
- Execution order of MySQL query statements join, on and where
- MySQL and excel tables importing database data (Excel for MySQL)
- 微信全文搜索技术优化
- (4) Pyqt5 tutorial -- > Custom signal and slot (super winding...)
- ECSHOP whole site custom URL supports directory type
- Ubuntu uninstalling PHP
- 最大数[抽象排序之抽象规则]
- The whole page turns gray
- JS array length is defined
- Windows下MySQL的安装和删除
猜你喜欢

MySQL common interview questions

Laravel excel export

GPS receiver design (1)

Idea2017 how to set not to automatically open a project at startup

MySQL and excel tables importing database data (Excel for MySQL)

顺序表的折半查找法

Embedded software development written examination and interview notes (latest update: February 17, 2022)

(2) Pyqt5 tutorial -- > using qtdesigner to separate interface code

Zhangxiaobai's road to penetration (7) -sql injection detailed operation steps -union joint query injection

为何数据库也云原生了?
随机推荐
node. JS architecture optimization: reverse proxy and cache service
A commonly used statistical modeling method -- difference analysis
Tidb common commands
Shell learning notes (latest update: 2022-02-18)
Total number of MySQL statistics, used and unused
Zhangxiaobai's road of penetration (VI) -- the idea and process of SQL injection and the concat series functions and information of SQL_ Schema database explanation
Tp6 exception handling try catch writing method
Three jobs! You can learn this from me (attached with graduation vlog)
Laravel task scheduling
Zhangxiaobai's road of penetration (IV) -- detailed explanation of XSS cross site script vulnerabilities
K8s, docker compose install MySQL 8.0.18
地理空间搜索:kd树的实现原理
The whole page turns gray
Flutter automatically disappears after receiving push
MySQL common interview questions
Execution order of MySQL query statements join, on and where
The source code of the hottest online disk money making system in 2022 imitates Lanzou online disk / Chengtong online disk / sharing money making cloud disk system / online disk VIP Download System
Go novice exploration road 1
Possible causes of wechat applet decryption failure
Maximum number [abstract rules for abstract sorting]