0%

java | com.alibaba.fastjson

fastjson是阿里巴巴的开源JSON解析库,它可以解析JSON格式的字符串,支持将Java Bean序列化为JSON字符串,也可以从JSON字符串反序列化到JavaBean。


参考资料



模版数据


1
2
3
4
5
6
7
8
9
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
41
42
43
44
45
{
"status": 0,
"deploy": true,
"date": "2019-11-11 10:52:27.811321",
"message": "complex vehicle json sample",
"data": {
"archived": false,
"creator": "Anchor",
"time": "2019-11-11 11:30:26",
"brands": [
{
"id": 1205231,
"type": "LUXURY",
"name_zh": "奔驰",
"name_en": "Benz",
"createDate": "1844-11-25",
"subsidiary": ["smart", "GLC", "GLA"],
"popular": [{
"model": "S350L",
"color": "White"
},
{
"model": "C260",
"color": "Silver"
}]
},
{
"id": 1324561,
"type": "REALISTIC",
"name_zh": "长安",
"name_en": "CHANGAN",
"createDate": "1996-10-31",
"subsidiary": ["Passenger", "SUV", "MPV"],
"popular": [{
"model": "CS75",
"color": "Red"
},
{
"model": "XT",
"color": "Black"
}]
}
]
}
}

三个类


JSON类

Json转换器(解析器),将Json文本转换成Json对象JSONObjectJSONArray等)或Java对象,也可将JsonJava对象转换成Json文本

JSONObject类

Json文本转换成的Json对象,可从中读取Json文本中的数据。

JSONArray类

Json文本转换成的Json对象,与JSONObject不同的是JSONArray是个数组。遍历时将JSONArray中的每个元素转换成JSONObject,然后读取数据。

请我喝杯咖啡吧~