http://blog.csdn.net/lucky_bo/article/details/47657641
Gson parsing arrays and list containers
Using Gson parsing first needs to join the rack package file: Gson-2.2.4.jar
Define a class of student:
public class Student {
String name= "Xiao";
String sex= "Male";
}
To define a Java file:
public class Listtogson {
public static void Main (string[] args) {
Student[] people= new Student[]{new Student (), New Student (), New Student ()};
arraylist<student> list = new arraylist<student> ();
List.add (New Student ());
List.add (New Student ());
List.add (New Student ());
String json = new Gson (). ToJson (list);
String peoples = new Gson (). ToJson (people);
SYSTEM.OUT.PRINTLN (JSON);
SYSTEM.OUT.PRINTLN (peoples);
}
}
The results of the operation are as follows:
Parsing the list: [{"Name": "Xiao", "Sex": "Male"},{"name": "Xiao", "Sex": "Male"},{"name": "Xiao", "Sex": "Male"}]
Log group Resolution: [{"Name": "Xiao", "Sex": "Male"},{"name": "Xiao", "Sex": "Male"},{"name": "Xiao", "Sex": "Male"}]
Gson parsing arrays array and list container