Home > Article > Web Front-end > JSON format data serialization and deserialization
Test class:
Package edu.xjtu.lee;
Imported java.util.ArrayList;
Imported java.util.List;
Import net.sf.json.JSONArray;
Import net.sf.json. JSONSerializer;
public class JSONArrayTest {
private static List
list.add(新Stu(1,"力强","fasdfas"));
list.add(新Stu(2,"Zhaoyu","dfasdfasdfas"));
list.add(new statu(3,"techdetection","fasdffsdafas"));
list.add(new statu(4"menglirong","fasdfsdafasdfas"));
jsonStr = JSONSerializer.toJSON(list) ToString();
}
public static void Deserializer() {
JSONArray JA = JSONArray.fromObject(jsonStr);
@SuppressWarnings("Not Registered")
List
for(int i = 0; I
}
public static void main( String[] args) {
Serializer();
Deserializer();
}
}
Bean definition:
Package edu.xjtu.lee;
Public class Stu{
Private int ID;
Private String Name;
Private String Description;
Stu() {}
Stu(INT ID, String Name, String DESC) {
this.id = ID;
this.name = name;
this.desc = description;
}
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 String getPhone() {
Diminishing returns;
}
public void setPhone(String DESC) {
this.desc = decrement;
}
}