当前位置:网站首页>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;
}
边栏推荐
- PHP微信抢红包的算法
- the installer has encountered an unexpected error installing this package
- Static keyword
- Ventuz Foundation Series "one step at the door"
- tslib库的移植
- Pat class a 1028 list sorting
- 华为S5700交换机初始化和配置telnet,ssh用户方法
- OSPF protocol summary
- How can entrepreneurial teams implement agile testing to improve quality and efficiency? Voice network developer entrepreneurship lecture Vol.03
- Professor Zhang Yang of the University of Michigan is employed as a visiting professor of Shanghai Jiaotong University, China (picture)
猜你喜欢
一篇文章让你读懂-曼彻斯特编码
Pat class a 1031 Hello world for u
【cocos creator】点击按钮切换界面
Redis batch startup and shutdown script
the installer has encountered an unexpected error installing this package
HDMI2.1与HDMI2.0的区别以及转换PD信号。
Ventuz Foundation Series "one step at the door"
[MySQL 14] use dbeaver tool to remotely backup and restore MySQL database (Linux Environment)
Unity2019_ Lighting system
Harmonyos third training notes
随机推荐
Unity dotween sequence animation replay problem.
freetype库的移植
Huawei switches are configured with SSH login remote management switches
[at] ABC 258g - Triangle triples reachable - violence
haproxy+keepalived搭建01
Client server model
RM delete file
the installer has encountered an unexpected error installing this package
[at] ABC 258g - triple Reach - violence
JS common basic case sorting (continuous update)
P2704 [NOI2001] 炮兵阵地(状压dp)
[at] abc 258G - Triangle 三元組可達-暴力
Unity XR realizes interaction (grasping, moving, rotating, transmitting, shooting) -pico
My touch screen production "brief history" 2
P2622 关灯问题II(状态压缩 搜索)
idea取消引用显示效果
idea取消引用顯示效果
WorldView卫星遥感影像数据/米级分辨率遥感影像
LwIP learning socket (API)
Technology dry goods | Roberta of the migration of mindspore NLP model - emotion analysis task