Fastjson 介绍和使用

来源:互联网 发布:adobe cc 2017 mac 编辑:程序博客网 时间:2024/06/13 21:40

=

为什么使用fastjson

fastjson在大量数据的情况下速度最快:http://blog.csdn.net/zml_2015/article/details/52165317

引入fastjson

通过Maven引入fastjson

<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson --><dependency>    <groupId>com.alibaba</groupId>    <artifactId>fastjson</artifactId>    <version>1.2.31</version></dependency>

fastjsonAPI介绍

工具类中

1.parse:字符串或者文本转JSON对象
2.toJSON…,Object对象转JSON
3.JSON对象的put添加方法
4.JSON对象的remove方法

public class JSONTest {    @Test    public void print() {        JSONObject jsonObject = new JSONObject();        jsonObject.put("1", 1);        jsonObject.put("2", 2);        jsonObject.remove("3", 3);        User user = new User();        user.setUserName("Hello");        jsonObject.put("user", JSONObject.toJSON(user));        System.out.println(jsonObject);        String json=jsonObject.toJSONString();        JSONObject jsonObject1 = JSONObject.parseObject(json);        jsonObject1.put("123",1);        System.out.println(jsonObject1);    }}
{"1":1,"2":2,"user":{"userName":"Hello"}}{"1":1,"2":2,"123":1,"user":{"userName":"Hello"}}

大量解析JSON

大量解析格式化JSON不卡的地方:
http://www.bejson.com/jsonviewernew/

原创粉丝点击