Home  >  Article  >  Web Front-end  >  JSON format data serialization and deserialization

JSON format data serialization and deserialization

巴扎黑
巴扎黑Original
2016-12-20 16:16:421182browse

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 = List(List ) JSONArray.toCollection(JA,Stu.class);
for(int i = 0; I 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;

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;
}


}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn