当前位置:网站首页>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边栏推荐
- Apache server OpenSSL upgrade
- B_ QuRT_ User_ Guide(33)
- I want to know who I need to know to open a stock account? In addition, is it safe to open a mobile account?
- Which direction should college students choose to find jobs after graduation?
- 机器学习中如何使用数据集?
- 软件确认测试的内容和流程有哪些?确认测试报告需要多少钱?
- Based on the open source stream batch integrated data synchronization engine Chunjun data restore DDL parsing module actual combat sharing
- Some memory problems summarized
- Using Obsidian with Hugo, markdown's local editing software is seamlessly connected with online
- 《安富莱嵌入式周报》第270期:2022.06.13--2022.06.19
猜你喜欢

win11更新后任务栏空白怎么办? win11更新后任务栏空白卡死的解决方法

JD and Tencent renewed the three-year strategic cooperation agreement; The starting salary rose to 260000 yuan, and Samsung sk of South Korea scrambled for a raise to retain semiconductor talents; Fir

谈谈数字化转型的几个关键问题

机器学习中如何使用数据集?

A new one from Ali 25K came to the Department, which showed me what the ceiling is
![[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

与AI结对编程式是什么体验 Copilot vs AlphaCode, Codex, GPT-3

腾讯3年,功能测试进阶自动化测试,送给在手工测试中迷茫的你

Which direction should college students choose to find jobs after graduation?
![[introduction to MySQL] the first conversation · first time in the](/img/73/cc85eb469384c3df94479318293c6f.png)
[introduction to MySQL] the first conversation · first time in the "database" Mainland
随机推荐
将Nagios监控信息存入MySQL
电脑版微信文件存储在哪个文件夹可以找到
Which direction should college students choose to find jobs after graduation?
msf之ms17-010永恒之蓝漏洞
机器学习中如何使用数据集?
Analysis of PostgreSQL storage structure
[BSP video tutorial] BSP video tutorial issue 19: AES encryption practice of single chip bootloader, including all open source codes of upper and lower computers (June 26, 2022)
latex字母头顶两个点
Stinky tofu made by Grandma
Excuse me, can I open an account for the company? Is it safe? All the answers you want are here
牛逼|珍藏多年的工具让我实现了带薪摸鱼自由
B_ QuRT_ User_ Guide(35)
1. Summary of wechat applet page Jump methods; 2. the navigateto stack does not jump to the tenth floor
On several key issues of digital transformation
I want to know who I need to know to open a stock account? In addition, is it safe to open a mobile account?
Vite2 is compatible with lower versions of chrome (such as Sogou 80). Some grammars requiring higher versions are processed through polyfills
Is there a shortage? No need to download the free online resources! 2022 favorites must have it!
Do a scrollbar thinking
Store Nagios monitoring information into MySQL
HDFS centralized cache management