jsontest.java

来自「java与Json实例」· Java 代码 · 共 37 行

JAVA
37
字号
package action;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

public class JsonTest {

	public static void main(String[] args) {
		
		JsonConfig cfg=new JsonConfig();
		cfg.registerJsonValueProcessor(java.util.Date.class, new JsonValueProcessorImpl());
		cfg.registerJsonValueProcessor(java.sql.Date.class, new JsonValueProcessorImpl());
//        JSONObject json = JSONObject.fromObject(student,cfg);   
//        System.out.println(json);
		List list=new ArrayList();
		Student student=new Student(); 
		student.setName("普罗米修斯");
		student.setAge(12);
		student.setBirthday(new Date());
		list.add(student);
		student=new Student(); 
		student.setName("基础");
		student.setAge(22);
		student.setBirthday(new Date());
		list.add(student);
        JSONArray array = JSONArray.fromObject(list,cfg);
        System.out.println(array);
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?