Androidstudio--gsonformat

Source: Internet
Author: User

Long ago, write JSON parsing with the original method of parsing JSON, and later in order to speed up the development process, began to use Gson,fastjson and other third-party jar package for JSON parsing, in order to keep the apk small enough, not because the introduction of JAR package caused the apk file too large, Choose to use Gson to speed up JSON parsing, of course, last year Androidstudio 1.0 release, many people began to use Androidstudio, of course, studio has a lot of easy to develop plug-ins to accelerate the development of applications, reduce the developer's workforce.

Today recommended a tool is: Gsonformat:https://github.com/zzz40500/gsonformat after use, how so sour, haha installation process:setting-->plugins--> Use: Customize a JavaBean (Nothing, just an empty class) first copy the JSON you want to parse and then alt+insert the following interface to paste into the following interface: Click OK to automatically generate the corresponding JavaBean statement: then JSON to The conversion of beans provides two tool classes:
  1. 1 Importjava.util.List;2 /**3 * Todo:json Tool class4  * 5  * @authorSoyoungboy6 * @date 2014-11-8 pm 2:32:247  */8  Public Abstract classJson {9     Private StaticJSON JSON;Ten Json () { One     } A      Public StaticJson Get () { -         if(JSON = =NULL) { -JSON =NewGsonimpl (); the         } -         returnJSON; -     } -      Public AbstractString ToJson (Object src); +      Public Abstract<T> T Toobject (String json, class<t>Claxx); -      Public Abstract<T> T Toobject (byte[] Bytes, class<t>Claxx); +      Public Abstract<T> list<t> toList (String json, class<t>Claxx); A}
    1  Public classGsonimplextendsJson {2     PrivateGson Gson =NewGson ();3 @Override4      PublicString ToJson (Object src) {5         returnGson.tojson (SRC);6     }7 @Override8      Public<T> T Toobject (String json, class<t>Claxx) {9         returnGson.fromjson (JSON, Claxx);Ten     } One @Override A      Public<T> T Toobject (byte[] Bytes, class<t>Claxx) { -         returnGson.fromjson (NewString (bytes), claxx); -     } the @Override -      Public<T> list<t> toList (String json, class<t>Claxx) { -Type type =NewTypetoken<arraylist<t>>() {}.gettype ();  -list<t> list =Gson.fromjson (JSON, type);  +         returnlist; -     } +}

Then there is a sentence that perfectly parses the JSON:
    1. 1 JavaBean Bean =gsonimpl.get (). Toobject (Json,javabean. Class);
The perfect parsing of JSON is so simple that it's so sour. The tool class for parsing JSON comes from the wheel code of Lite's GitHub. Https://github.com/litesuits/android-lite-http/tree/master/library/src/com/litesuits/http/data

Androidstudio--gsonformat

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.