Testklasse:
Paket edu.xjtu.lee;imported java.util.ArrayList;
imported java.util.List; json.JSONArray;
import net.sf.json.JSONSerializer;
private static list
public static void Serializer() {
list = new ArrayList
list.add(new stuff(1, "力强", "fasdfas")); >list.add(新Stu(2,"Zhaoyu","dfasdfasdfas")); new Stu(4 "menglirong", "fasdfsdafasdfas"));
jsonStr = JSONSerializer.toJSON(list)ToString();
}
public static void Deserializer() {
JSONArray JA = JSONArray.fromObject(jsonStr);
@SuppressWarnings("unregistered")
List
System.out.println(list.get(I).getId()+""+list.get(I).getName()+ ""+list.get().getPhone());
}
public static void main(string[] args) {
serializer();
deserializer( }
}
Bean-Definition:
package edu.xjtu.lee;
public class Stu{
private int ID
Privater String-Name;
Privater String-Beschreibung;
Stu() {}
Stu(INT ID, String-Name, String DESC) {
this .id = ID;
this.desc = Beschreibung;
public int getId() {
return ID; }
public void SETID (INT ID) {
this.id = ID;
}
public string getName() {
return name;
Public void setname can (String name) {
this.name = name;
public void setPhone(String DESC) {
this.desc = Decrement;
}
}