- 浏览: 38891 次
- 性别:
- 来自: 北京
最新评论
fastjson 是一个性能很好的 Java 语言实现的 JSON 解析器和生成器,来自阿里巴巴的工程师开发。
主要特点:
- 快速FAST (比其它任何基于Java的解析器和生成器更快,包括jackson)
- 强大(支持普通JDK类包括任意Java Bean Class、Collection、Map、Date或enum)
- 零依赖(没有依赖其它任何类库除了JDK)
示例代码:
import com.alibaba.fastjson.JSON; Group group = new Group(); group.setId(0L); group.setName("admin"); User guestUser = new User(); guestUser.setId(2L); guestUser.setName("guest"); User rootUser = new User(); rootUser.setId(3L); rootUser.setName("root"); group.getUsers().add(guestUser); group.getUsers().add(rootUser);String jsonString = JSON.toJSONString(group);System.out.println(jsonString);
官方网站:http://www.open-open.com/lib/view/home/1324131055937
一、JSON规范
JSON是一个标准规范,用于数据交互,规范的中文文档如下:
参看规范,来对比JSON类库处理结果。
二、fastjson的一些简要说明
1、了解fastjson
Fastjson介绍
Fastjson是一个Java语言编写的JSON处理器。
1、遵循http://json.org标准,为其官方网站收录的参考实现之一。
2、功能qiang打,支持JDK的各种类型,包括基本的JavaBean、Collection、Map、Date、Enum、泛型。
3、无依赖,不需要例外额外的jar,能够直接跑在JDK上。
4、开源,使用Apache License 2.0协议开源。http://code.alibabatech.com/wiki/display/FastJSON/Home
1、遵循http://json.org标准,为其官方网站收录的参考实现之一。
2、功能qiang打,支持JDK的各种类型,包括基本的JavaBean、Collection、Map、Date、Enum、泛型。
3、无依赖,不需要例外额外的jar,能够直接跑在JDK上。
4、开源,使用Apache License 2.0协议开源。http://code.alibabatech.com/wiki/display/FastJSON/Home
如果获得Fastjson?
SVN:http://code.alibabatech.com/svn/fastjson/trunk/
WIKI:http://code.alibabatech.com/wiki/display/FastJSON/Home
Issue Tracking:http://code.alibabatech.com/jira/browse/FASTJSON
SVN:http://code.alibabatech.com/svn/fastjson/trunk/
WIKI:http://code.alibabatech.com/wiki/display/FastJSON/Home
Issue Tracking:http://code.alibabatech.com/jira/browse/FASTJSON
2、主要的使用入口
Fastjson API入口类是com.alibaba.fastjson.JSON,常用的序列化操作都可以在JSON类上的静态方法直接完成。
public static final Object parse(String text); // 把JSON文本parse为JSONObject或者JSONArray
public static final JSONObject parseObject(String text); // 把JSON文本parse成JSONObject
public static final <T> T parseObject(String text, Class<T> clazz); // 把JSON文本parse为JavaBean
public static final JSONArray parseArray(String text); // 把JSON文本parse成JSONArray
public static final <T> List<T> parseArray(String text, Class<T> clazz); //把JSON文本parse成JavaBean集合
public static final String toJSONString(Object object); // 将JavaBean序列化为JSON文本
public static final String toJSONString(Object object, boolean prettyFormat); // 将JavaBean序列化为带格式的JSON文本
public static final Object toJSON(Object javaObject); 将JavaBean转换为JSONObject或者JSONArray。
public static final JSONObject parseObject(String text); // 把JSON文本parse成JSONObject
public static final <T> T parseObject(String text, Class<T> clazz); // 把JSON文本parse为JavaBean
public static final JSONArray parseArray(String text); // 把JSON文本parse成JSONArray
public static final <T> List<T> parseArray(String text, Class<T> clazz); //把JSON文本parse成JavaBean集合
public static final String toJSONString(Object object); // 将JavaBean序列化为JSON文本
public static final String toJSONString(Object object, boolean prettyFormat); // 将JavaBean序列化为带格式的JSON文本
public static final Object toJSON(Object javaObject); 将JavaBean转换为JSONObject或者JSONArray。
3、有关类库的一些说明
SerializeWriter:相当于StringBuffer
JSONArray:相当于List<Object>
JSONObject:相当于Map<String, Object>
JSON反序列化没有真正数组,本质类型都是List<Object>
4、fastjson还有很多很高级的特性,比如支持注解、支持全类型序列化,这些都是很好的特性,功能强大,不在本次测试范围。
三、测试代码
package lavasoft.stu.json;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer;
import java.util.*;
/**
* Created by IntelliJ IDEA.
*
* @author leizhimin 11-11-22 上午9:15
*/
public class Foo {
private String vString = "vStringhehhehe";
private char vchar = 'x';
private byte vbyte = 64;
private short vshort = 128;
private int vint = 65535;
private long vlong = 9999999L;
private float vfloat = 12.1f;
private double vdouble = 22.203d;
private boolean vboolean = false;
// private Date vdate = new Date();
private Date dddd = new Date();
private Date vDate = new Date();
private Date v_Date = new Date();
private Object vnull = null;
private String[] avString = {"aaa", "bbb", "ccc"};
private int[] avint = {1, 2, 3, 4};
private boolean[] avboolean = {true, false, true, true};
private List<String> listString = new ArrayList<String>();
private Map<String, String> map = new HashMap<String, String>();
private Bar bar = new Bar();
private Bar[] avBar = {new Bar(), new Bar()};
private List<Bar> listBar = new ArrayList<Bar>();
{
listString.add("listString1");
listString.add("listString2");
listString.add("listString3");
map.put("x", "s11111x");
map.put("y", "s22222y");
map.put("z", "s33333z");
listBar.add(new Bar());
listBar.add(new Bar());
listBar.add(new Bar());
}
public String getvString() {
return vString;
}
public void setvString(String vString) {
this.vString = vString;
}
public char getVchar() {
return vchar;
}
public void setVchar(char vchar) {
this.vchar = vchar;
}
public byte getVbyte() {
return vbyte;
}
public void setVbyte(byte vbyte) {
this.vbyte = vbyte;
}
public short getVshort() {
return vshort;
}
public void setVshort(short vshort) {
this.vshort = vshort;
}
public int getVint() {
return vint;
}
public void setVint(int vint) {
this.vint = vint;
}
public long getVlong() {
return vlong;
}
public void setVlong(long vlong) {
this.vlong = vlong;
}
public float getVfloat() {
return vfloat;
}
public void setVfloat(float vfloat) {
this.vfloat = vfloat;
}
public double getVdouble() {
return vdouble;
}
public void setVdouble(double vdouble) {
this.vdouble = vdouble;
}
public boolean isVboolean() {
return vboolean;
}
public void setVboolean(boolean vboolean) {
this.vboolean = vboolean;
}
public Date getDddd() {
return dddd;
}
public void setDddd(Date dddd) {
this.dddd = dddd;
}
public Date getV_Date() {
return v_Date;
}
public void setV_Date(Date v_Date) {
this.v_Date = v_Date;
}
public Date getvDate() {
return vDate;
}
public void setvDate(Date vDate) {
this.vDate = vDate;
}
public Object getVnull() {
return vnull;
}
public void setVnull(Object vnull) {
this.vnull = vnull;
}
public String[] getAvString() {
return avString;
}
public void setAvString(String[] avString) {
this.avString = avString;
}
public int[] getAvint() {
return avint;
}
public void setAvint(int[] avint) {
this.avint = avint;
}
public boolean[] getAvboolean() {
return avboolean;
}
public void setAvboolean(boolean[] avboolean) {
this.avboolean = avboolean;
}
public List<String> getListString() {
return listString;
}
public void setListString(List<String> listString) {
this.listString = listString;
}
public Map<String, String> getMap() {
return map;
}
public void setMap(Map<String, String> map) {
this.map = map;
}
public Bar getBar() {
return bar;
}
public void setBar(Bar bar) {
this.bar = bar;
}
public Bar[] getAvBar() {
return avBar;
}
public void setAvBar(Bar[] avBar) {
this.avBar = avBar;
}
public List<Bar> getListBar() {
return listBar;
}
public void setListBar(List<Bar> listBar) {
this.listBar = listBar;
}
}
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer;
import java.util.*;
/**
* Created by IntelliJ IDEA.
*
* @author leizhimin 11-11-22 上午9:15
*/
public class Foo {
private String vString = "vStringhehhehe";
private char vchar = 'x';
private byte vbyte = 64;
private short vshort = 128;
private int vint = 65535;
private long vlong = 9999999L;
private float vfloat = 12.1f;
private double vdouble = 22.203d;
private boolean vboolean = false;
// private Date vdate = new Date();
private Date dddd = new Date();
private Date vDate = new Date();
private Date v_Date = new Date();
private Object vnull = null;
private String[] avString = {"aaa", "bbb", "ccc"};
private int[] avint = {1, 2, 3, 4};
private boolean[] avboolean = {true, false, true, true};
private List<String> listString = new ArrayList<String>();
private Map<String, String> map = new HashMap<String, String>();
private Bar bar = new Bar();
private Bar[] avBar = {new Bar(), new Bar()};
private List<Bar> listBar = new ArrayList<Bar>();
{
listString.add("listString1");
listString.add("listString2");
listString.add("listString3");
map.put("x", "s11111x");
map.put("y", "s22222y");
map.put("z", "s33333z");
listBar.add(new Bar());
listBar.add(new Bar());
listBar.add(new Bar());
}
public String getvString() {
return vString;
}
public void setvString(String vString) {
this.vString = vString;
}
public char getVchar() {
return vchar;
}
public void setVchar(char vchar) {
this.vchar = vchar;
}
public byte getVbyte() {
return vbyte;
}
public void setVbyte(byte vbyte) {
this.vbyte = vbyte;
}
public short getVshort() {
return vshort;
}
public void setVshort(short vshort) {
this.vshort = vshort;
}
public int getVint() {
return vint;
}
public void setVint(int vint) {
this.vint = vint;
}
public long getVlong() {
return vlong;
}
public void setVlong(long vlong) {
this.vlong = vlong;
}
public float getVfloat() {
return vfloat;
}
public void setVfloat(float vfloat) {
this.vfloat = vfloat;
}
public double getVdouble() {
return vdouble;
}
public void setVdouble(double vdouble) {
this.vdouble = vdouble;
}
public boolean isVboolean() {
return vboolean;
}
public void setVboolean(boolean vboolean) {
this.vboolean = vboolean;
}
public Date getDddd() {
return dddd;
}
public void setDddd(Date dddd) {
this.dddd = dddd;
}
public Date getV_Date() {
return v_Date;
}
public void setV_Date(Date v_Date) {
this.v_Date = v_Date;
}
public Date getvDate() {
return vDate;
}
public void setvDate(Date vDate) {
this.vDate = vDate;
}
public Object getVnull() {
return vnull;
}
public void setVnull(Object vnull) {
this.vnull = vnull;
}
public String[] getAvString() {
return avString;
}
public void setAvString(String[] avString) {
this.avString = avString;
}
public int[] getAvint() {
return avint;
}
public void setAvint(int[] avint) {
this.avint = avint;
}
public boolean[] getAvboolean() {
return avboolean;
}
public void setAvboolean(boolean[] avboolean) {
this.avboolean = avboolean;
}
public List<String> getListString() {
return listString;
}
public void setListString(List<String> listString) {
this.listString = listString;
}
public Map<String, String> getMap() {
return map;
}
public void setMap(Map<String, String> map) {
this.map = map;
}
public Bar getBar() {
return bar;
}
public void setBar(Bar bar) {
this.bar = bar;
}
public Bar[] getAvBar() {
return avBar;
}
public void setAvBar(Bar[] avBar) {
this.avBar = avBar;
}
public List<Bar> getListBar() {
return listBar;
}
public void setListBar(List<Bar> listBar) {
this.listBar = listBar;
}
}
package lavasoft.stu.json;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer;
import java.util.Date;
import java.util.Random;
/**
* Created by IntelliJ IDEA.
*
* @author leizhimin 11-11-22 上午9:15
*/
public class Bar {
public static SerializeConfig mapping = new SerializeConfig();
private String barName;
private int barAge;
private Date barDate = new Date();
static {
mapping.put(Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd"));
}
{
Random r = new Random();
barName = "sss_"+String.valueOf(r.nextFloat());
barAge = r.nextInt();
}
public static void main(String[] args) {
Object obj = JSON.toJSON(new Bar());
String x1 = JSON.toJSONString(new Bar(), true);
System.out.println(x1);
String x2 = JSON.toJSONString(new Bar(), mapping);
System.out.println(x2);
}
public String getBarName() {
return barName;
}
public void setBarName(String barName) {
this.barName = barName;
}
public int getBarAge() {
return barAge;
}
public void setBarAge(int barAge) {
this.barAge = barAge;
}
public Date getBarDate() {
return barDate;
}
public void setBarDate(Date barDate) {
this.barDate = barDate;
}
@Override
public String toString() {
return "Bar{" +
"barName='" + barName + '\'' +
", barAge=" + barAge +
", barDate=" + barDate +
'}';
}
}
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer;
import java.util.Date;
import java.util.Random;
/**
* Created by IntelliJ IDEA.
*
* @author leizhimin 11-11-22 上午9:15
*/
public class Bar {
public static SerializeConfig mapping = new SerializeConfig();
private String barName;
private int barAge;
private Date barDate = new Date();
static {
mapping.put(Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd"));
}
{
Random r = new Random();
barName = "sss_"+String.valueOf(r.nextFloat());
barAge = r.nextInt();
}
public static void main(String[] args) {
Object obj = JSON.toJSON(new Bar());
String x1 = JSON.toJSONString(new Bar(), true);
System.out.println(x1);
String x2 = JSON.toJSONString(new Bar(), mapping);
System.out.println(x2);
}
public String getBarName() {
return barName;
}
public void setBarName(String barName) {
this.barName = barName;
}
public int getBarAge() {
return barAge;
}
public void setBarAge(int barAge) {
this.barAge = barAge;
}
public Date getBarDate() {
return barDate;
}
public void setBarDate(Date barDate) {
this.barDate = barDate;
}
@Override
public String toString() {
return "Bar{" +
"barName='" + barName + '\'' +
", barAge=" + barAge +
", barDate=" + barDate +
'}';
}
}
package lavasoft.stu.json;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer;
import java.util.*;
/**
* Created by 2IntelliJ IDEA.
*
* @author leizhimin 11-11-22 上午9:45
*/
public class Test {
private static SerializeConfig mapping = new SerializeConfig(); static {
mapping.put(Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd HH:mm:ss"));
}
public static void main(String[] args) {
Foo f1 = new Foo();
Date date = new Date();
String text = JSON.toJSONString(date, mapping);
System.out.println(text);
System.out.println(JSON.toJSONString(f1, true));
String x2 =JSON.toJSONString(f1, mapping);
System.out.println(x2);
}
public static void json2List(){
//List -> JSON array
List<Bar> barList = new ArrayList<Bar>();
barList.add(new Bar());
barList.add(new Bar());
barList.add(new Bar());
String json= JSON.toJSONString(barList, true);
System.out.println(json);
//JSON array -> List
List<Bar> barList1 = JSON.parseArray(json,Bar.class);
for (Bar bar : barList1) {
System.out.println(bar.toString());
}
}
public static void json2Map(){
//Map -> JSON
Map<String,Bar> map = new HashMap<String, Bar>();
map.put("a",new Bar());
map.put("b",new Bar());
map.put("c",new Bar());
String json = JSON.toJSONString(map,true);
System.out.println(json);
//JSON -> Map
Map<String,Bar> map1 = (Map<String,Bar>)JSON.parse(json);
for (String key : map1.keySet()) {
System.out.println(key+":"+map1.get(key));
}
}
public static void array2JSON(){
String[] arr_String = {"a","b","c"};
String json_arr_String = JSON.toJSONString(arr_String,true);
System.out.println(json_arr_String);
JSONArray jsonArray = JSON.parseArray(json_arr_String);
for (Object o : jsonArray) {
System.out.println(o);
}
System.out.println(jsonArray);
}
public static void array2JSON2(){
Bar[] arr_Bar = {new Bar(),new Bar(),new Bar()};
String json_arr_Bar = JSON.toJSONString(arr_Bar,true);
System.out.println(json_arr_Bar);
JSONArray jsonArray = JSON.parseArray(json_arr_Bar);
for (Object o : jsonArray) {
System.out.println(o);
}
System.out.println(jsonArray);
}
public static void map2JSON(){
Map map = new HashMap();
map.put("a","aaa");
map.put("b","bbb");
map.put("c","ccc");
String json=JSON.toJSONString(map);
System.out.println(json);
Map map1 = JSON.parseObject(json);
for (Object o : map.entrySet()) {
Map.Entry<String,String> entry = (Map.Entry<String,String>)o;
System.out.println(entry.getKey()+"--->"+entry.getValue());
}
}
}
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer;
import java.util.*;
/**
* Created by 2IntelliJ IDEA.
*
* @author leizhimin 11-11-22 上午9:45
*/
public class Test {
private static SerializeConfig mapping = new SerializeConfig(); static {
mapping.put(Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd HH:mm:ss"));
}
public static void main(String[] args) {
Foo f1 = new Foo();
Date date = new Date();
String text = JSON.toJSONString(date, mapping);
System.out.println(text);
System.out.println(JSON.toJSONString(f1, true));
String x2 =JSON.toJSONString(f1, mapping);
System.out.println(x2);
}
public static void json2List(){
//List -> JSON array
List<Bar> barList = new ArrayList<Bar>();
barList.add(new Bar());
barList.add(new Bar());
barList.add(new Bar());
String json= JSON.toJSONString(barList, true);
System.out.println(json);
//JSON array -> List
List<Bar> barList1 = JSON.parseArray(json,Bar.class);
for (Bar bar : barList1) {
System.out.println(bar.toString());
}
}
public static void json2Map(){
//Map -> JSON
Map<String,Bar> map = new HashMap<String, Bar>();
map.put("a",new Bar());
map.put("b",new Bar());
map.put("c",new Bar());
String json = JSON.toJSONString(map,true);
System.out.println(json);
//JSON -> Map
Map<String,Bar> map1 = (Map<String,Bar>)JSON.parse(json);
for (String key : map1.keySet()) {
System.out.println(key+":"+map1.get(key));
}
}
public static void array2JSON(){
String[] arr_String = {"a","b","c"};
String json_arr_String = JSON.toJSONString(arr_String,true);
System.out.println(json_arr_String);
JSONArray jsonArray = JSON.parseArray(json_arr_String);
for (Object o : jsonArray) {
System.out.println(o);
}
System.out.println(jsonArray);
}
public static void array2JSON2(){
Bar[] arr_Bar = {new Bar(),new Bar(),new Bar()};
String json_arr_Bar = JSON.toJSONString(arr_Bar,true);
System.out.println(json_arr_Bar);
JSONArray jsonArray = JSON.parseArray(json_arr_Bar);
for (Object o : jsonArray) {
System.out.println(o);
}
System.out.println(jsonArray);
}
public static void map2JSON(){
Map map = new HashMap();
map.put("a","aaa");
map.put("b","bbb");
map.put("c","ccc");
String json=JSON.toJSONString(map);
System.out.println(json);
Map map1 = JSON.parseObject(json);
for (Object o : map.entrySet()) {
Map.Entry<String,String> entry = (Map.Entry<String,String>)o;
System.out.println(entry.getKey()+"--->"+entry.getValue());
}
}
}
说明:
SerializeConfig:是对序列化过程中一些序列化过程的特殊配置,这里用作日期格式的定义。
有关需要带类型的全类型序列化过程,需要调用JSON.toJSONStringZ()方法。
需要美化输出时候,需要打开序列化美化开关,在方法中true那个参数。
输出结果:
"2011-11-23 23:30:33"
{
"avBar":[{
"barAge":174398800,
"barDate":1322062233062,
"barName":"sss_0.62378174"
},{
"barAge":38938962,
"barDate":1322062233062,
"barName":"sss_0.36014742"
}],
"avString":["aaa","bbb","ccc"],
"avboolean":[true,false,true,true],
"avint":[1,2,3,4],
"bar":{
"barAge":1601495948,
"barDate":1322062233062,
"barName":"sss_0.46644872"
},
"dddd":1322062233046,
"listBar":[
{
"barAge":-1090113522,
"barDate":1322062233062,
"barName":"sss_0.83562374"
},
{
"barAge":478603194,
"barDate":1322062233062,
"barName":"sss_0.59483266"
},
{
"barAge":1118357669,
"barDate":1322062233062,
"barName":"sss_0.9961642"
}
],
"listString":[
"listString1",
"listString2",
"listString3"
],
"map":{"x":"s11111x","y":"s22222y","z":"s33333z"},
"v_Date":1322062233046,
"vboolean":false,
"vbyte":64,
"vchar":"x",
"vdouble":22.203,
"vfloat":12.1,
"vint":65535,
"vlong":9999999,
"vshort":128
}
{"avBar":[{"barAge":174398800,"barDate":"2011-11-23 23:30:33","barName":"sss_0.62378174"},{"barAge":38938962,"barDate":"2011-11-23 23:30:33","barName":"sss_0.36014742"}],"avString":["aaa","bbb","ccc"],"avboolean":[true,false,true,true],"avint":[1,2,3,4],"bar":{"barAge":1601495948,"barDate":"2011-11-23 23:30:33","barName":"sss_0.46644872"},"dddd":"2011-11-23 23:30:33","listBar":[{"barAge":-1090113522,"barDate":"2011-11-23 23:30:33","barName":"sss_0.83562374"},{"barAge":478603194,"barDate":"2011-11-23 23:30:33","barName":"sss_0.59483266"},{"barAge":1118357669,"barDate":"2011-11-23 23:30:33","barName":"sss_0.9961642"}],"listString":["listString1","listString2","listString3"],"map":{"x":"s11111x","y":"s22222y","z":"s33333z"},"v_Date":"2011-11-23 23:30:33","vboolean":false,"vbyte":64,"vchar":"x","vdouble":22.203,"vfloat":12.1,"vint":65535,"vlong":9999999,"vshort":128}
Process finished with exit code 0
{
"avBar":[{
"barAge":174398800,
"barDate":1322062233062,
"barName":"sss_0.62378174"
},{
"barAge":38938962,
"barDate":1322062233062,
"barName":"sss_0.36014742"
}],
"avString":["aaa","bbb","ccc"],
"avboolean":[true,false,true,true],
"avint":[1,2,3,4],
"bar":{
"barAge":1601495948,
"barDate":1322062233062,
"barName":"sss_0.46644872"
},
"dddd":1322062233046,
"listBar":[
{
"barAge":-1090113522,
"barDate":1322062233062,
"barName":"sss_0.83562374"
},
{
"barAge":478603194,
"barDate":1322062233062,
"barName":"sss_0.59483266"
},
{
"barAge":1118357669,
"barDate":1322062233062,
"barName":"sss_0.9961642"
}
],
"listString":[
"listString1",
"listString2",
"listString3"
],
"map":{"x":"s11111x","y":"s22222y","z":"s33333z"},
"v_Date":1322062233046,
"vboolean":false,
"vbyte":64,
"vchar":"x",
"vdouble":22.203,
"vfloat":12.1,
"vint":65535,
"vlong":9999999,
"vshort":128
}
{"avBar":[{"barAge":174398800,"barDate":"2011-11-23 23:30:33","barName":"sss_0.62378174"},{"barAge":38938962,"barDate":"2011-11-23 23:30:33","barName":"sss_0.36014742"}],"avString":["aaa","bbb","ccc"],"avboolean":[true,false,true,true],"avint":[1,2,3,4],"bar":{"barAge":1601495948,"barDate":"2011-11-23 23:30:33","barName":"sss_0.46644872"},"dddd":"2011-11-23 23:30:33","listBar":[{"barAge":-1090113522,"barDate":"2011-11-23 23:30:33","barName":"sss_0.83562374"},{"barAge":478603194,"barDate":"2011-11-23 23:30:33","barName":"sss_0.59483266"},{"barAge":1118357669,"barDate":"2011-11-23 23:30:33","barName":"sss_0.9961642"}],"listString":["listString1","listString2","listString3"],"map":{"x":"s11111x","y":"s22222y","z":"s33333z"},"v_Date":"2011-11-23 23:30:33","vboolean":false,"vbyte":64,"vchar":"x","vdouble":22.203,"vfloat":12.1,"vint":65535,"vlong":9999999,"vshort":128}
Process finished with exit code 0
fastjson通过各方面测试都很好,功能性能都是No.1,喜欢,它的源代码质量很高,作者也煞费苦心,将性能做到了最好,全免超越其他的json类库。
从其中的源代码中,可以学到很多东西,在阅读源码后,不得不佩服作者高超的程序设计水平,和高质量的编码。
感谢alibaba对此工具开源。
fastjson-1.1.10-sources.jar
由于fastjson缺乏良好的api文档,在阅读源码过程中,参考了网上一些文档:
相关推荐
在渗透测试中遇到json数据一般都会测试下有没有反序列化,然而JSON库有Fastjson,JackJson,Gson等等,那么怎么判断后端不是Fastjson呢?可以构造特定的payload来进行探测分析
这是一个封装好的FastJson工具类、里面已经处理各种情况~分享给大家
fastjson-1.2.80和简单工具类,用来学习jsonpath,目前使用的是fastjson1.0版本而不是2.0版本。
FastJson对于json格式字符串的解析主要用到了下面三个类: 1.JSON:fastJson的解析器,用于JSON格式字符串与JSON对象及javaBean之间的转换 2.JSONObject:fastJson提供的json对象 3.JSONArray:fastJson提供json...
总的来说,这个主题涵盖了JSON处理和二进制数据序列化的关键知识点,包括Fastjson和protobuf的基本概念、工作原理、性能评估以及如何在实际项目中进行选型和测试。对于Java开发者来说,理解和掌握这些内容对于优化...
**Fastjson:一个高效、强大的Java JSON库** Fastjson是阿里巴巴开发的一个开源项目,它是一个Java语言编写的高性能功能完备的JSON库。Fastjson能够将Java对象转换为JSON字符串,也能将JSON内容转换为对应的Java...
**FastJson:一个高效、强大的Java JSON库** FastJson是阿里巴巴开源的一款高性能的JSON库,它主要用于Java对象与JSON字符串之间的转换。在这个小例子中,我们将深入探讨FastJson的使用方法,以及它如何帮助开发者...
在这个“fastjson实用工具类”中,我们可以找到一系列帮助我们更便捷地操作JSON对象的方法。下面将详细介绍Fastjson库的一些核心功能和常见用法。 1. JSON字符串与Java对象之间的转换 - `parseObject(String json...
总结来说,Fastjson作为Java世界里解析JSON的利器,凭借其高效的性能和简洁的API,成为了广大开发者不可或缺的工具。无论是新手还是经验丰富的开发人员,都能在Fastjson的帮助下轻松处理JSON数据,提升开发效率。...
这个文件名可能是测试fastJSON功能的一个测试类,通常会包含一系列的单元测试,用于验证序列化、反序列化、类型转换等功能是否正常工作。开发者可以通过这些测试确保fastJSON在特定场景下的正确性。 7. **源码分析...
总的来说,Alibaba FastJson是一个强大而实用的JSON处理工具,它的高效性能和丰富的特性使得它在Java社区中广受欢迎。无论是在企业级应用还是小型项目中,FastJson都能提供稳定且高效的JSON处理方案。学习并熟练掌握...
5. **性能优势**:FastJSON在多个测试场景下表现出比其他同类库更高的解析速度,尤其在大数据量处理时,其性能优势更为明显。 **二、核心概念** 1. **JSONParser和JSONWriter**:这两个类是FastJSON的核心,它们...
SpringBoot 2.0 整合 Fastjson 是一个常见的任务,因为Fastjson是阿里巴巴提供的一款高性能的JSON库,它能够方便地进行Java对象与JSON数据之间的转换。在SpringBoot项目中,Fastjson可以帮助我们快速处理JSON格式的...
在标题“fastjson1.2.2.rar”和描述中,我们可以推断出这是一个关于 Fastjson 版本 1.2.2 的资源包。这个压缩文件包含了两个主要的组件:`fastjson-1.2.2.jar` 和 `fastjson-1.2.2-sources.jar`。 1. **fastjson-...
FastJSON是阿里巴巴开发的一款高性能的Java JSON库,它提供了快速且便捷的方式来处理JSON数据。FastJSON不仅支持将Java对象转换为JSON字符串,还能将JSON字符串反序列化为Java对象,极大地简化了Java与JSON之间的...
在这个类中,我们可以定义一个静态方法`formatJson(String jsonString)`,该方法接收一个未格式化的JSON字符串,然后利用Fastjson提供的API进行格式化处理。 ```java import com.alibaba.fastjson.JSON; import ...
在“jxxt-fastjson”这个压缩包中,可能包含了实现这个功能的源代码、配置文件示例、以及相关的测试用例。通过分析这些内容,我们可以深入理解如何在实际项目中实施这个定制的Fastjson别名配置化方案。同时,了解这...
主要针对常用的json工具Gson,jackson,fastjson进行性能测试,一个完整的工程,包含测试类、测试结论,以及三个工具包的jar文件。可以直接在eclipse中运行。具体版本如下: fastjson-1.1.28.jar gson-1.7.1.jar ...
标题中的“http请求测试实例(采用fastjson解析)”指的是使用HTTP...总之,这个主题涵盖了HTTP请求的基础知识、Fastjson库的使用以及如何在Java项目中进行集成和测试。理解这些内容对于开发和测试网络应用非常重要。
Fastjson是一个Java语言编写的JSON处理器。 1、遵循http://json.org标准,为其官方网站收录的参考实现之一。 2、功能qiang打,支持JDK的各种类型,包括基本的JavaBean、Collection、Map、Date、Enum、泛型。 3、无...