当前位置:网站首页>Fastjson V2 简单使用手册
Fastjson V2 简单使用手册
2022-06-30 22:13:00 【InfoQ】
前言
JSONJSONJSECMA262ECMA404rfc4627JSONJSONJSONJSONfalsenulltrueobjectarraynumberstring{}key:value[],JSON{
"baseInfo": {
"name": "cunyu1943",
"wepublic": "村雨遥",
"wechat": "cunyu1024",
"platform": ["juejin", "CSDN", "Github", "zhihu"]
}
}
JSONFastjson:国内阿里巴巴公司所开发的JSON库,性能出众且快速。
Jackson:Spring默认的JSON库,社区十分活跃,更新迭代快。
Gson:谷歌出品的JSON库,算是目前来说功能最全的JSON库了。
FastjsonFastjsonJSONFastjson使用技巧
MavenFastjsonFastjson v2MavenMavenpom.xmlFastjson V2<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.6</version>
</dependency>
Hero@Data
@NoArgsConstructor
@AllArgsConstructor
public class Hero {
private String sex;
private String name;
private String profession;
}
Java 对象序列化为 JSON
HerotoJSONString()JSONpublic class MainApplication {
public static void main(String[] args) {
// Java 对象转 JSON
Hero hero = new Hero("女", "虞姬", "射手");
String heroJson = JSON.toJSONString(hero);
System.out.println(heroJson);
}
}

JSON 解析为 Java 对象
JSONparseObject()public class MainApplication {
public static void main(String[] args) {
// JSON 字符串转 Java 对象
String shooter = "{"name":"伽罗","profession":"射手","sex":"女"}";
Hero hero = JSON.parseObject(shooter, Hero.class);
System.out.println(hero.toString());
}
}

JSON 解析为 JSONObject
JSONJSONObjectJSONpublic class MainApplication {
public static void main(String[] args) {
// JSON 解析为 JSONObject
String shooter = "{"name":"黄忠","profession":"射手","sex":"男"}";
JSONObject heroJson = JSON.parseObject(shooter);
System.out.println(heroJson.toJSONString());
}
}

JSON 解析为 JSONArray
JSONJSONArrayparseArray()public class MainApplication {
public static void main(String[] args) {
// JSON 解析为 JSONArray
String platform = "[{"name":"CSDN","id":"村雨遥"},{"name":"Juejin","id":"村雨遥"}]";
JSONArray platformArray = JSON.parseArray(platform);
System.out.println(platformArray.toJSONString());
}
}

总结
JSONJSONFastjson V2Fastjson V2边栏推荐
- Spark - understand partitioner in one article
- Turn: win others' follow with practical actions
- 将Nagios监控信息存入MySQL
- The programmer's girlfriend gave me a fatigue driving test
- Mysql:sql overview and database system introduction | dark horse programmer
- Develop technology - get time 10 minutes ago
- Excuse me, can I open an account for the company? Is it safe? All the answers you want are here
- The Three Musketeers: One for All!
- How to judge whether the JS object is empty
- 基于kubernetes平台微服务的部署
猜你喜欢

How to realize the center progress bar in wechat applet
![Flip the linked list ii[three ways to flip the linked list +dummyhead/ head insertion / tail insertion]](/img/a8/6472e2051a295f5e42a88d64199517.png)
Flip the linked list ii[three ways to flip the linked list +dummyhead/ head insertion / tail insertion]

Best wishes for Lao Wu's party
![[450. delete nodes in binary search tree]](/img/fd/bab2f92edeadd16263f15de6cc4420.png)
[450. delete nodes in binary search tree]

Golang application ━ installation, configuration and use of Hugo blog system

2022中国国潮发展新动向

Nansen double disk encryption giant self rescue: how to prevent the collapse of billions of dominoes

Win11如何优化服务?Win11优化服务的方法
![[career planning for Digital IC graduates] Chap.1 overview of IC industry chain and summary of representative enterprises](/img/d3/68c9d40ae6e61efc10aca8bcc1f613.jpg)
[career planning for Digital IC graduates] Chap.1 overview of IC industry chain and summary of representative enterprises

1. Summary of wechat applet page Jump methods; 2. the navigateto stack does not jump to the tenth floor
随机推荐
B_ QuRT_ User_ Guide(35)
I want to know who I need to know to open a stock account? In addition, is it safe to open a mobile account?
msf之ms17-010永恒之蓝漏洞
牛逼|珍藏多年的工具让我实现了带薪摸鱼自由
Is the stock account opened in qiniu safe? How to apply for a low commission stock account?
[backtracking] full arrangement leetcode46
Best wishes for Lao Wu's party
Tencent has been conducting advanced automated functional testing for 3 years. It is a gift to you who are confused in manual testing
How to design test cases
About, Qianxin detects code vulnerabilities and XSS series solves them
Online education program user login and registration
Web APIs comprehensive case -tab column switching - dark horse programmer
Qsort function and Simulation Implementation of qsort function
5g demand in smart medicine
总结的一些内存问题
latex左侧大括号 latex中大括号多行公式
Nansen double disk encryption giant self rescue: how to prevent the collapse of billions of dominoes
机器学习工作要求研究生吗?
Anti leakage family photo in attack and defense drill
Anfulai embedded weekly report no. 271: June 20, 2022 to June 26, 2022