Use of Fastjson in Andorid

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.