当前位置:网站首页>JSON与Object之间转换
JSON与Object之间转换
2022-07-03 07:56:00 【八荒.】
在开发过程种;往往需要进行复杂数据的存储,我们一般使用json字符串的形式存储复杂数据,废话不多说上案例:**
使用net的JSON**
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
1:字符串json转化对象实体类对象或者集合
//对象集合转化json字符串
List<Test> allorderList = new ArrayList();
JSONArray exportDataJson = JSONArray.fromObject(allorderList);
String exportData = exportDataJson.toString();
//json字符串转化对象集合
JSONArray jsonArray = JSONArray.fromObject(json);
List<Test> reportVoList =JSONArray.toList(jsonArray, Test.class);
2:字符串json与 复杂集合的相应转化
/**
*
* List<Map<String, Object>>数据 转化json字符串存储数据
* @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信息转化 List<Map<String, Object>>数据
* @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;
}
边栏推荐
- 【LeetCode】2. Valid parentheses · valid parentheses
- C2-关于VCF文件合并的几种方法
- Huawei switch: configure Telnet, SSH and web access
- oracle 插入单引号
- 在浏览器输入url后执行什么
- Technical dry goods Shengsi mindspire dynamic transformer with variable sequence length has been released!
- JS common basic case sorting (continuous update)
- idea取消引用顯示效果
- 华为交换机:配置telnet和ssh、web访问
- PostGIS space function
猜你喜欢

haproxy+keepalived集群搭建02

Pycharm remote ssh pyenv error: pydev debugger: warning: trying to add breakpoint to file that does

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

PostGIS space function

Go language foundation ----- 10 ----- string related operations (operation function, string conversion)

VMware virtual machine configuration static IP
![[cocos creator] Click the button to switch the interface](/img/b8/f0fd54a2a197cbfd788990e2806b52.png)
[cocos creator] Click the button to switch the interface

Iterm2设置

My touch screen production "brief history" 2
![[untitled]](/img/3d/27a7229e3f0ccf0ca5ae1f00a92513.jpg)
[untitled]
随机推荐
Harmonyos third training notes
华为交换机配置ssh登录远程管理交换机
WPF:解决MaterialDesign:DialogHost 无法关闭问题
MAE
What is definition? What is a statement? What is the difference between them?
Install cross compiler arm none liunx gnueabihf
Redis查看客户端连接
使用 FileChannel 进行文件的复制拷贝
Pat class a 1031 Hello world for u
PHP wechat red packet grabbing algorithm
P2704 [NOI2001] 炮兵阵地(状压dp)
Viz artist advanced script video tutorial -- stringmap use and vertex operation
MaxCompute字符串分割函数-SPLIT_PART
什麼是定義?什麼是聲明?它們有何區別?
RM delete file
Worldview satellite remote sensing image data / meter resolution remote sensing image
Microsoft Security Response Center
Idea unreference Display Effect
My touch screen production "brief history" 2
HDMI2.1与HDMI2.0的区别以及转换PD信号。