class="java">import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
public class TestJson {
public static void main(String[] args){
String jsonString = "";
ArrayList<String> list = new ArrayList<String>();
list.add("aa");
list.add("bb");
list.add("cc");
Date date = new Date();
Map<String, Object> map = new HashMap<String, Object>();
map.put("name", "chenx");
map.put("age", 12);
map.put("isGirl", false);
map.put("class", list);
map.put("time", date);
// jsonString 生成
jsonString =JSON.toJSONStringWithDateFormat(map,"yyyy-MM-dd HH:mm:ss.SSS");
// jsonString = JSON.toJSONString(map);
System.out.println(jsonString);
System.out.println(date);
// jsonString 解析
JSONObject jsonObject = JSON.parseObject(jsonString);
System.out.println("class[1] = " + jsonObject.getJSONArray("class").get(1));
System.out.println("time = " + jsonObject.getDate("time"));
System.out.println("time = " + jsonObject.getString("time"));
}
}