2、有关类库的一些说明
SerializeWriter:相当于StringBuffer
JSONArray:相当于List
JSONObject:相当于Map<String, Object>
JSON反序列化没有真正数组,本质类型都是List
3、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 listString = new ArrayList();
private Map<String, String> map = new HashMap<String, String>();
private Bar bar = new Bar();
private Bar[] avBar = {new Bar(), new Bar()};
private List listBar = new ArrayList();
{
listString.a