当前位置:网站首页>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 ~
边栏推荐
- Slice and slice methods of arrays in JS
- GPS NMEA protocol, 0183 positioning data format dual mode positioning: gnxxx gps+bd full version
- Write regular isosceles triangle and inverse isosceles triangle with for loop in JS
- PHP parsing QR code content
- Methods of strings in JS charat(), charcodeat(), fromcharcode(), concat(), indexof(), split(), slice(), substring()
- 聊聊高可用的 11 个关键技巧
- laravel 9
- Why do we do autocorrelation analysis? Explain application scenarios and specific operations
- GPS receiver design (1)
- sudo: ulimit: command not found
猜你喜欢

Singleton mode in PHP to reduce memory consumption

Execution order of MySQL query statements join, on and where

Three jobs! You can learn this from me (attached with graduation vlog)

Happy shopkeeper source code -- Introduction to happy shopkeeper system development mode

High performance + million level Excel data import and export

Installation and removal of MySQL under Windows

高性能负载均衡架构如何实现?

Guess Tongyuan B

QT TCP UDP network communication < theory >

ECSHOP commodity wholesale multi attribute multi specification multi inventory batch purchase ECSHOP wholesale plug-in ECSHOP multi attribute order
随机推荐
Thinkphp3 use phpword to modify the template and download it
Shell learning notes (latest update: 2022-02-18)
Laravel echart statistical chart line chart
High imitation blue playing network disk file sharing to make money network disk PHP system source code
Node child processes and threads
Network | indicators and test methods to measure the quality of the network
The first techo day Tencent technology open day in 2022 will be held online on June 28
Repair the error that ECSHOP background orders prompt insufficient inventory when adding goods. Please reselect
Thinkphp3 reinforcement i() function filter single quotation marks
JS function exercises
2022 meisai e topic ideas sharing + translation
High performance + million level Excel data import and export
2022 meisai topic C idea sharing + translation
ECSHOP quickly purchases goods, simplifies the shopping process, and improves the user experience through one-step shopping
MySQL common interview questions
Three jobs! You can learn this from me (attached with graduation vlog)
百度搜索稳定性问题分析的故事
初识CANOpen
Full nanny tutorial of Market Research Competition (experience sharing)
Disconnected: No supported authentication methods available (server sent: )