JSON工具之fastjson

来源:阿里巴巴
链接:https://github.com/Alibaba/fastjson/wiki/%E9%A6%96%E9%A1%B5

Fastjson是一个Java语言编写的高性能功能完善的JSON库。它采用一种“假定有序快速匹配”的算法,把JSON Parse的性能提升到极致,是目前Java语言中最快的JSON库。Fastjson接口简单易用,已经被广泛使用在缓存序列化、协议交互、Web输出、Android客户端等多种应用场景。

ToolLicenseURL
FastjsonApaceh 2.0https://github.com/alibaba/fastjson
GsonApaceh 2.0https://github.com/google/gson
JacksonApaceh 2.0https://github.com/FasterXML/jackson-core

常见问题解答

https://github.com/alibaba/fastjson/wiki/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98

下载

android 开发者请看 这里

最新 JAR

或者通过 Maven:

<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>fastjson</artifactId>
    <version>VERSION_CODE</version>
</dependency>

或者通过 Gradle:

compile 'com.alibaba:fastjson:VERSION_CODE'

用 这里 或者 这里 的真实发行版本号, 替换 VERSION_CODE , 例如 1.2.11

API

Fastjson parse Tree

import com.alibaba.fastjson.*;

JSONObject jsonObj = JSON.parseObject(jsonStr);

Fastjson parse POJO

import com.alibaba.fastjson.JSON;

Model model = JSON.parseObject(jsonStr, Model.class);

Fastjson parse POJO Generic

import com.alibaba.fastjson.JSON;

Type type = new TypeReference<List<Model>>() {}.getType(); 
List<Model> list = JSON.parseObject(jsonStr, type);

Fastjson convert POJO to json string

import com.alibaba.fastjson.JSON;

Model model = ...; 
String jsonStr = JSON.toJSONString(model);

Fastjson convert POJO to json bytes

import com.alibaba.fastjson.JSON;

Model model = ...; 
byte[] jsonBytes = JSON.toJSONBytes(model);

Fastjson write POJO as json string to OutputStream

import com.alibaba.fastjson.JSON;

Model model = ...; 
OutputStream os;
JSON.writeJSONString(os, model);

Fastjson write POJO as json string to Writer

import com.alibaba.fastjson.JSON;

Model model = ...; 
Writer writer = ...;
JSON.writeJSONString(writer, model);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值