작가:php.cn 업데이트 시간:2022-04-19 14:33:02
Fastjson API 비교
라이센스 및 프로젝트 URL
Maven
fastjson
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.11</version>
</dependency>
fastjson-android
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.1.51.android</version>
</dependency>
jackson
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.7.3</version>
</dependency>
gson
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.6.2</version>
</dependency>
API
Fastjson 구문 분석 Tree
import com.alibaba.fastjson.*;
JSONObject jsonObj = JSON.parseObject(jsonStr);
Fastjson 구문 분석 POJO
import com.alibaba.fastjson.JSON;
Model model = JSON.parseObject(jsonStr, Model.class
Fastjson은 POJO Generic을 구문 분석합니다.
import com.alibaba.fastjson.JSON;
Type type = new TypeReference<List<Model>>() {}.getType();
List<Model> list = JSON.parseObject(jsonStr, type);
Fastjson 변환 POJO를 json 문자열로
import com.alibaba.fastjson.JSON;
Model model = ...;
String jsonStr = JSON.toJSONString(model);
Fastjson POJO를 json 바이트로 변환
import com.alibaba.fastjson.JSON;
Model model = ...;
byte[] jsonBytes = JSON.toJSONBytes(model)
Fastjson POJO를 json 문자열로 OutputStream
import com.alibaba.fastjson.JSON;
Model model = ...;
OutputStream os;
JSON.writeJSONString(os, model);;
에 기록
Fastjson은 POJO를 Writer
import com.alibaba.fastjson.JSON;
Model model = ...;
Writer writer = ...;
JSON.writeJSONString(writer, model);