阿里巴巴 - FastJson使用简介
来源:互联网 发布:suse 重启端口 编辑:程序博客网 时间:2024/05/18 17:40
1.FastJSON简介
FastJSOn是阿里巴巴开源的JSON处理工具,大家可以尝试使用一下。
官网地址:http://code.alibabatech.com/wiki/display/FastJSON/Overview
Fastjson是一个json处理工具包,包括“序列化”和“反序列化”两部分,它具备如下特征:
- 速度最快,测试表明,fastjson具有极快的性能,超越任其他的java json parser。包括自称最快的jackson。
- 功能强大,完全支持java bean、集合、Map、日期、Enum,支持范型,支持自省。
- 无依赖,能够直接运行在Java SE 5.0以上版本
- 支持Android。
- 开源 (Apache 2.0)
2.简单使用
详细使用的话,大家可以去官网看,介绍很详细,而且是中文哦.
使用Maven的话,添加依赖:
<dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.1.36</version></dependency>
下面是简单的测试,参考官网上的数据
package org.ygy.fastjson;import org.junit.Test;import com.alibaba.fastjson.JSON;import com.alibaba.fastjson.JSONObject;import com.alibaba.fastjson.serializer.SerializerFeature;public class JSONTest{/** * * @author yuguiyang * @description 序列化 * @time 2013-9-12 * @version 1.0 */@Testpublic void test2JsonString() {User user = new User(100 , "lufei" , "shishi");String json = JSON.toJSONString(user);System.out.println(json);}/** * * @author yuguiyang * @description 反序列化为JSONObject对象 * @time 2013-9-12 * @version 1.0 */@Testpublic void testParseObject() {String json = JSON.toJSONString(new User(1002 , "suolong" , "shishi"));JSONObject obj = JSON.parseObject(json);System.out.println(obj);System.out.println(obj.get("id"));System.out.println(obj.getString("name"));}/** * * @author yuguiyang * @description 反序列化为JavaBean * @time 2013-9-12 * @version 1.0 */@Testpublic void testParseBean() {String json = JSON.toJSONString(new User(1002 , "suolong" , "shishi"));User user = JSON.parseObject(json , User.class);System.out.println(user.getId() + " , " + user.getName() + " , " + user.getPassword()); }/** * * @author yuguiyang * @description 将JavaBean对象转换为JSON对象 * @time 2013-9-12 * @version 1.0 */@Testpublic void test2Json() {User user = new User(222 , "qiaoba" , "haha");JSONObject obj = (JSONObject) JSON.toJSON(user);System.out.println(obj.get("id") + "," + obj.get("name"));}@Testpublic void testSeria() {User user = new User(222 , "qiaoba" , "haha");String json = JSON.toJSONString(user , SerializerFeature.WriteClassName);User juser = (User) JSON.parse(json);System.out.println(juser);}}
- 阿里巴巴 - FastJson使用简介
- 阿里巴巴 - FastJson使用简介
- 阿里巴巴 - FastJson使用简介
- 阿里巴巴fastjson的使用
- 阿里巴巴fastJson使用
- fastjson 阿里巴巴json使用
- 阿里巴巴的fastjson使用分析
- SpringMVC杂记(1) 使用阿里巴巴的fastjson
- Java编程:阿里巴巴的fastjson使用示例
- SpringMVC杂记(1) 使用阿里巴巴的fastjson
- Json解析包 阿里巴巴 FastJson 的使用
- Fastjson简介和基本使用
- Json简介及fastJson使用
- 阿里巴巴FastJson解析
- 阿里巴巴中的FastJson解析
- 阿里巴巴的fastJson
- 阿里巴巴fastjson简用
- 阿里巴巴的fastjson
- Day at the Race
- 【自定义标签】 java自定义标签
- alsa 细节
- 用merge into进行性能优化
- 百度对抗高德 移动导航app进入免费时代
- 阿里巴巴 - FastJson使用简介
- p115 E2
- ios 实现文字竖排
- eclipse中解除jdk的访问限制和打点提示(以BASE64Encoder/BASE64Decoder为例)
- 编程之美:三盏灯问题
- ucos:ucos 应用编程大全
- vc++常用函数总结
- android中Camera setDisplayOrientation使用
- android下eclipse中的Logcat 查看system.out.print()输出设置