Fastjson is Ali's Open source project, with the online version of the Fastjson resolution is Gson 6 times times, small size, and open source.
Project Address:
Https://github.com/alibaba/fastjson
The general JSON parser we all use is serialization and deserialization.
Let's take a look at the specific usage of Fastjson in the following example:
public class User { private Long ID; private String name; Public Long getId () { return ID; } public void SetId (Long id) { this.id = ID; } Public String GetName () { return name; } public void SetName (String name) { this.name = name; }}
public class Group { private Long ID; Private String name; Private list<user> users = new arraylist<user> (); Public Long getId () { return ID; } public void SetId (Long id) { this.id = ID; } Public String GetName () { return name; } public void SetName (String name) { this.name = name; } Public list<user> getusers () { return users; } public void Setusers (list<user> users) { this.users = users; }}
Group Group = new Group (); Group.setid (0L); Group.setname ("admin"); User Guestuser = new user (); Guestuser.setid (2L); Guestuser.setname ("Guest"); User Rootuser = New user (), Rootuser.setid (3L), rootuser.setname ("root"), Group.getusers (). Add (Guestuser); Group.getusers (). Add (Rootuser); String jsonstring = json.tojsonstring (group); System.out.println (jsonstring);
The above code input results are as follows:
{"id": 0, "name": "Admin", "users": [{"id": 2, "name": "Guest"},{"id": 3, "name": "Root"}]}
The deserialization operation is as follows:
Group Group = Json.parseobject (jsonstring, Group.class);
Fastjson Using Tutorials