当前位置:网站首页>new TypeReference用法 fastjson[通俗易懂]
new TypeReference用法 fastjson[通俗易懂]
2022-06-25 17:55:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
new TypeReference用法 fastjson
个人觉得涉及到的场景还是比较多的,多数我都用在调别人接口获取到的一些信息,然后映射实体的情况。 不知道这个方法的时候每次拿到一个字符串想去映射对象的时候,就jsonobject各种转换,转的自己都不想看自己写的代码,废话不多说上代码!!!
//这个new typeReference导入的包是package com.alibaba.fastjson;
//它还有一个包是package com.fasterxml.jackson.core.type;
/** *这是转成list的例子,转成对象还是map大体上差不多 **/
String provinces = readJsonFile(".//areaCode//provinces.json");
List<NationalCityCode> provinceList = jsonObject.parseObject(provinces, new TypeReference<List<NationalCityCode>>() {
});
for (NationalCityCode province : provinceList) {
redisTemplate.opsForValue().set(province.getCode(), province.getName());
}
/** *转成对象 **/
String provinces = readJsonFile(".//areaCode//provinces.json");
NationalCityCode province = jsonObject.parseObject(provinces, new TypeReference<NationalCityCode>() {
});
for (NationalCityCode province : provinceList) {
redisTemplate.opsForValue().set(province.getCode(), province.getName());
}
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/151110.html原文链接:https://javaforall.cn
边栏推荐
- CentOS7 安装 Redis 7.0.2
- Getting started with kotlin (20) several common dialog boxes
- Deeply understand and grasp the basic characteristics of digital economy
- The Stackies 2022:32个营销技术栈入选
- 怎么判断自己是否适合转行软件测试
- Mobile heterogeneous computing technology - GPU OpenCL programming (basic)
- golang sort slice int
- SDN system method | 9 Access network
- New characteristics of cultural consumption in the era of digital economy
- The performance of the server's four channel memory is improved. How about the performance of the four channel memory
猜你喜欢
有关均衡----简易版瓶颈模型
Distributed remote management of distribution room environment
Why do we need ankeri's active power filter in frequency converter occasions?
篇4:win10安装MingW64
Precautions for the use of Jerry's wake-up mouth [chapter]
About Equilibrium - Simplified bottleneck model
[matlab] data interpolation
[compilation principle] overview
什么是算子?
为什么在变频器场合需要安科瑞的电力有源滤波器?
随机推荐
一些常用的知识点积累
Recursion and divide and conquer
Jerry's ADC_ get_ Incorrect voltage value obtained by voltage function [chapter]
The icon is missing. What does the URL come from with the jesssionid?
How to open a stock account is it safe to open an account
Which of the top ten securities companies has the lowest commission? Is it safe to open an account
[matlab] curve fitting
移动端异构运算技术 - GPU OpenCL 编程(基础篇)
User scheduling problem
数据挖掘之时间序列分析[通俗易懂]
Unity technical manual - interference / noise sub module
喜报|海泰方圆通过CMMI-3资质认证,研发能力获国际认可
配电室环境的分布式远程管理
Using QT to make a beautiful login interface box
158_模型_Power BI 使用 DAX + SVG 打通制作商业图表几乎所有可能
深入理解ELF文件
Utilisation de diskgenius pour augmenter la capacité du disque système C
lock
Hover effect of eight buttons
使用DiskGenius拓展系统盘C盘的容量