当前位置:网站首页>Conversion between JSON and object
Conversion between JSON and object
2022-07-03 07:58:00 【Eight wastelands】
In the development process ; It is often necessary to store complex data , We usually use json Storing complex data in the form of strings , No more nonsense, let's talk about the case :**
Use net Of JSON**
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
1: character string json Convert object entity class object or collection
// Object collection conversion json character string
List<Test> allorderList = new ArrayList();
JSONArray exportDataJson = JSONArray.fromObject(allorderList);
String exportData = exportDataJson.toString();
//json String conversion object collection
JSONArray jsonArray = JSONArray.fromObject(json);
List<Test> reportVoList =JSONArray.toList(jsonArray, Test.class);
2: character string json And The corresponding transformation of complex sets
/**
*
* List<Map<String, Object>> data conversion json String storage data
* @param json
* @return
*
*/
List<Map> list = new ArrayList();
Map map = new HashMap();
map.put("deptName",i.getDeptName());
List<CaterHistoryBusinessReportVO> lunchResult=new ArrayList();
List<CaterHistoryBusinessReportVO> dinnerResult=new ArrayList();
map.put("morningList",lunchResult);
map.put("dinnerList",dinnerResult);
list.add(map);
JSONArray jsonArray = JSONArray.fromObject(list);
String jsonResult = jsonArray.toString();
/**
*
* json Information transformation List<Map<String, Object>> data
* @param json
* @return
*
*/‘
public static List<Map<String, Object>> toListMap(String json) {
List<Object> list = JSON.parseArray(json);
List<Map<String, Object>> listw = new ArrayList<Map<String, Object>>();
for (Object object : list) {
Map<String, Object> ret = (Map<String, Object>) object;
listw.add(ret);
}
return listw;
}
边栏推荐
- I want to do large screen data visualization application feature analysis
- Huawei s5700 switch initialization and configuration SSH and telnet remote login methods
- [at] abc 258G - Triangle 三元组可达-暴力
- Project experience sharing: handwritten Chinese character recognition based on Shengsi mindspire
- experiment.........
- PHP常用排序算法
- MAE
- Demonstration of plug-in use of ventuz basic series
- An intern's journey to cnosdb
- [end of 2021] National Meteorological Short Video (Kwai, Tiktok) influence list in December
猜你喜欢

haproxy+keepalived集群搭建02

OSPF experiment

在浏览器输入url后执行什么

JS common basic case sorting (continuous update)

vcs import src < ros2. Repos failed

What is a data type? What is the use of data types?

IP production stream is so close to me

How can entrepreneurial teams implement agile testing to improve quality and efficiency? Voice network developer entrepreneurship lecture Vol.03

freetype库的移植

Pat grade a 1029 median
随机推荐
JS common basic case sorting (continuous update)
Go language foundation ----- 19 ----- context usage principle, interface, derived context (the multiplexing of select can be better understood here)
Huawei s5700 switch initialization and configuration Telnet, SSH user methods
Introduction of novel RNA based cancer therapies
Quality blog——
JS regular case-
一个实习生的CnosDB之旅
华为交换机:配置telnet和ssh、web访问
Redis view client connection
MaxCompute字符串分割函数-SPLIT_PART
How can entrepreneurial teams implement agile testing to improve quality and efficiency? Voice network developer entrepreneurship lecture Vol.03
Docker installs MySQL and successfully uses Navicat connection
Unity2019_ Lighting system
LwIP learning socket (API)
【cocos creator】点击按钮切换界面
[untitled]
Getting started with minicom
What to do after the browser enters the URL
Pycharm remote ssh pyenv error: pydev debugger: warning: trying to add breakpoint to file that does
haproxy+keepalived集群搭建02