首页 > 代码库 > java json-lib.jar

java json-lib.jar

 

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

import net.sf.json.JSONObject;

public class Test {

public static void main(String[] args) {
Mybean bean = new Test().new Mybean();
bean.setId("001");
bean.setName("银行卡");
bean.setDate(new Date());
List cardNum = new ArrayList();
cardNum.add("农行");
cardNum.add("工行");
cardNum.add("建行");
cardNum.add(new Person("test"));
bean.setCardNum(cardNum);
JSONObject jsonObject = JSONObject.fromObject(bean);
System.out.println(jsonObject);

}

//内部类
public class Mybean{
private String id;
private String name;
private Date date;
private List cardNum;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public List getCardNum() {
return cardNum;
}
public void setCardNum(List cardNum) {
this.cardNum = cardNum;
}
}
}

  

java json-lib.jar