FastJson详解
来源:互联网 发布:上海巨人网络生活区 编辑:程序博客网 时间:2024/05/13 16:52
速度最快,测试表明,fastjson具有极快的性能,超越任其他的Java Json parser。包括自称最快的JackJson;
功能强大,完全支持Java Bean、集合、Map、日期、Enum,支持范型,支持自省;无依赖,能够直接运行在Java SE 5.0以上版本;支持Android;开源 (Apache 2.0)
二、特点
Fastjson是一个Java语言编写的JSON处理器。1、遵循http://json.org标准,为其官方网站收录的参考实现之一。2、功能qiang打,支持JDK的各种类型,包括基本的JavaBean、Collection、Map、Date、Enum、泛型。3、无依赖,不需要例外额外的jar,能够直接跑在JDK上。4、开源,使用Apache License 2.0协议开源。
三、 使用方法说明
public
public
public
public
public
public
public
四、demo
代码:
Useruser = new User();
user.setId(100);
user.setName("xxx");
StringstrJson = JSON.toJSONString(user);
System.out.println("######1:"+strJson+":"+JSON.parseObject(strJson,User.class).getId());
List<User>list = new ArrayList<>();
list.add(user);
strJson = JSON.toJSONString(list);
System.out.println("######1:"+strJson+":");
user =new User();
user.setId(200);
user.setName("yyy");
list.add(user);
strJson = JSON.toJSONString(list);
System.out.println("######2:"+strJson+":"+JSON.parseArray(strJson, User.class).get(1).getName());
Map<Object,Object>map = new HashMap<>();
map.put("userInfos",list);
map.put("company","mw");
strJson = JSON.toJSONString(map);
System.out.println("######3:"+strJson+":"+JSON.parseObject(strJson).get("company"));
List<User>users = new ArrayList<User>();
users = JSON.parseArray(JSON.parseObject(strJson).get("userInfos").toString(),User.class);
System.out.println("######4:"+users.size()+":"+users.get(0).getName());
输出结果:######1:{"id":100,"name":"xxx"}:100
######1:[{"id":100,"name":"xxx"}]:
######2:[{"id":100,"name":"xxx"},{"id":200,"name":"yyy"}]:yyy
######3:{"company":"mw","userInfos":[{"id":100,"name":"xxx"},{"id":200,"name":"yyy"}]}:mw
######4:2:xxx
- FastJson详解
- fastJson 详解
- FastJSON实现详解
- FastJson使用详解
- 静行:FastJSON实现详解
- FastJson使用详解Demo
- FastJson 使用详解
- FastJSON实现详解
- FastJSON实现详解
- FastJson.API详解
- fastjson SerializerFeature详解
- FastJson的使用详解
- fastjson SerializerFeature详解
- fastjson SerializerFeature详解
- fastjson SerializerFeature详解
- fastjson SerializerFeature详解
- fastjson的使用详解
- fastjson SerializerFeature详解
- has been modified the precompiled header (路径)was built;
- 公网里是否能走私网路由
- Git的忽略文件的语法规则
- 初始化56个名族下拉选框
- 各种数据库对应的jar包、驱动类名和URL格式
- FastJson详解
- 设计模式学习(单例模式)
- RN入门
- uboot.2015.07移植之裁剪uboot以及驱动yaffs(9)
- OpenWrt patch补丁的方法
- python——字符串
- leetcode Palindrome Linked List
- HDOJ 3555 Bomb
- SprignMVC+myBatis整合(一)—— 基于MapperFactoryBean