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 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 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