一、JSON的概述
我们做项目,通常会使用前后端分离的ajax交互,那么前后端交互的数据格式通常是json格式。这里既有牵扯到json和对象集合之间的转换,目前市面上的json转换主要有三种:
- Jackson转换
- FastJson转换
- Gson转换
下面将会对这三种转换进行简单的入门演示:
二、准备工作
1、新建一个maven工程
工程名任意,打包方式选择jar
2、在pom.xml导入下面依赖
[XML] 纯文本查看 复制代码
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
< dependencies >
< dependency >
< groupId >com.alibaba</ groupId >
< artifactId >fastjson</ artifactId >
< version >1.2.58</ version >
</ dependency >
< dependency >
< groupId >com.fasterxml.jackson.core</ groupId >
< artifactId >jackson-databind</ artifactId >
< version >2.8.1</ version >
</ dependency >
< dependency >
< groupId >com.google.code.gson</ groupId >
< artifactId >gson</ artifactId >
< version >2.8.1</ version >
</ dependency >
< dependency >
< groupId >junit</ groupId >
< artifactId >junit</ artifactId >
< version >4.11</ version >
< scope >compile</ scope >
</ dependency >
</ dependencies >
< build >
< plugins >
<!-- java编译插件 -->
< plugin >
< groupId >org.apache.maven.plugins</ groupId >
< artifactId >maven-compiler-plugin</ artifactId >
< version >3.7.0</ version >
< configuration >
< source >1.8</ source >
< target >1.8</ target >
< encoding >UTF-8</ encoding >
</ configuration >
</ plugin >
</ plugins >
</ build >
|
3、创建用于演示的类
[Java] 纯文本查看 复制代码
01
02
03
04
05
06
07
|