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

JSON format data serialization and deserialization

巴扎黑
Release: 2016-12-20 16:16:42
Original
1215 people have browsed it

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


}

Related labels:
source:php.cn
Statement of this Website
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
Latest Issues
Backslash present in Json
From 1970-01-01 08:00:00
0
0
0
Get: Transfer JSON data
From 1970-01-01 08:00:00
0
0
0
mysql storage json error
From 1970-01-01 08:00:00
0
0
0
javascript - Problems with displaying json data
From 1970-01-01 08:00:00
0
0
0
Find matching integers in JSON.
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template