Description: Fastjson is currently the fastest JSON library in the Java language, faster than claiming the fastest Jackson speed, and third-party independent test results see this :https://github.com/eishay/ Jvm-serializers/wiki/staging-results .
Fastjson is about 6 times times faster than Gson, and the test results are here:https://github.com/eishay/jvm-serializers/wiki/Staging-Results
How to use:
For example, parse data in the following format:
{"id": 1, "name": "User", "result": [{"id": 2, "name": "Child1"},{"id": 3, "name": "Child2"}]}
1. Code:
Group g = Json.parseobject (str, group.class); STR to parse string n = g.getname (); list<user> US = g.getuserlist (); for (User u:us) { android.util.log.d ("Mark", "u=" + u.getname ()); } ANDROID.UTIL.LOG.D ("Mark", "n=" + N);
Package Com.example.domain;import Java.util.arraylist;import Java.util.list;import Com.alibaba.fastjson.annotation.jsonfield;public class Group { private int id; private String name; Private list<user> userslist = new arraylist<user> (); public int getId () { return ID; } public void setId (int id) { this.id = ID; } Public String GetName () { return name; } public void SetName (String name) { this.name = name; } Public list<user> getuserlist () { return userslist; } @JSONField (name = "Result") //Use annotations to facilitate the processing of the results sent by the server public void Setuserlist (list<user> userslist) { this.userslist = userslist; }}
Package Com.example.domain;public class User { private int id; private String name; public int getId () { return ID; } public void setId (int id) { this.id = ID; } Public String GetName () { return name; } public void SetName (String name) { this.name = name; }}
2, do not forget to add the corresponding Fastjson.jar package jar package Download Click to open the link
Use of Fastjson in Andorid