当前位置:网站首页>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;
}
边栏推荐
- JS to implement publish and subscribe
- 华为S5700交换机初始化和配置telnet,ssh用户方法
- [MySQL 12] MySQL 8.0.18 reinitialization
- P1896 [SCOI2005] 互不侵犯(状压dp)
- Go language foundation ----- 19 ----- context usage principle, interface, derived context (the multiplexing of select can be better understood here)
- Pat class a 1032 sharing
- Huawei switch basic configuration (telnet/ssh login)
- JS regular case-
- 【踩坑系列】mysql 修改root密码失败
- MaxCompute字符串分割函数-SPLIT_PART
猜你喜欢

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

【cocos creator】点击按钮切换界面

What to do after the browser enters the URL

Pat grade a 1029 median

the installer has encountered an unexpected error installing this package

JS common basic case sorting (continuous update)
![[cocos creator] Click the button to switch the interface](/img/b8/f0fd54a2a197cbfd788990e2806b52.png)
[cocos creator] Click the button to switch the interface

EtherCAT state machine transition (ESM)
![[untitled]](/img/3d/27a7229e3f0ccf0ca5ae1f00a92513.jpg)
[untitled]

Technical dry goods | thinking about the unification of dynamic and static diagrams of AI framework
随机推荐
Docker installs MySQL and successfully uses Navicat connection
[untitled]
璞华PLM为全场景产品生命周期管理赋能,助力产品主线的企业数字化转型
My touch screen production "brief history" 2
Idea dereference display effect
JSON与Object之间转换
优质博客——
register关键字
Harmonyos third training notes
jsutlis
华为交换机基础配置(telnet/ssh登录)
Demonstration of plug-in use of ventuz basic series
Product creation and commercial realization of chat robot (according to La Ma Bang - Dr. Wang Jingjing - speech)
一篇文章让你读懂-曼彻斯特编码
P2704 [NOI2001] 炮兵阵地(状压dp)
Retail philosophy retail psychological warfare after reading -- 7-11 is a good product!
Technology dry goods | Roberta of the migration of mindspore NLP model - emotion analysis task
Redis查看客户端连接
OSPF protocol summary
Go language foundation ----- 19 ----- context usage principle, interface, derived context (the multiplexing of select can be better understood here)