Overview
I believe that everyone in the process of development has written a lot of javabean, many cases are a list of data is a separate javabean, if you knock the words of time and effort is easy to knock the wrong.
Today we recommend a plug-in Gsonformat This plugin is to let us directly return the service to the JSON into the entity class, Android studio and idea have, eclipse I have not tried. You can look for any.
Operation StepsFirst step Download plugin
The process of downloading the plugin I have a blog in front of the detailed steps of the Android Studio plugin sexy editor (set as background) everyone just need to change the name of the plugin described in the blog to Gsonformat
Follow that step to download the plugin. Remember to restart when the download is installed!
The second step is to generate the bean automatically
Here we describe how to automatically generate the JSON returned by the server via this plugin JavaBean
First we want to build an empty Java class, and then right-click on the blank left mouse button to select Generate ... If you have successfully installed the plugin, the following box will pop up.
Selecting Gsonformat will pop up the box below
Paste the JSON returned by the service back into this and click OK.
Clicking OK after pasting will pop up as shown in the Select field interface
This interface is to allow you to choose which fields to keep, perhaps some of the fields do not need to put the front of the check out. Finally click OK and you are done.
Paste the JSON string and the automatically generated bean code.
JSON string
<span style= "FONT-SIZE:14PX;" >{"RetVal": "OK", "Reterr": "", "Retinfo": {"Count": 2, "groups": [{"GroupID": 1, "title": "\U65B0\U670B\U53CB", "icon" : "Http:\/\/aliimg.yizhibo.tv\/online\/message\/2f\/74\/hi.png", "type": "1", "readcnt": "Unread": 2, "total": 19, " Update_time ":" 2016-04-05 09:11:09 "," lastest_content ": {" type ": 2," data ": {" name ":" 16837286 "," nickname ":" \u963f\ U83b2 "," gender ":" Female "," signature ":" "," VIP ":" 0 "," Logourl ":" Http:\/\/aliimg.yizhibo.tv\/online\/user\/2c\/17\ /[email protected]_100w_90q_0e_1c "}}},{" GroupID ": 0," title ":" \u6613\u76f4\u64ad\u5c0f\u79d8\u4e66 "," icon ": "Http:\/\/aliimg.yizhibo.tv\/online\/message\/07\/fd\/secretary.png", "type": 0, "readcnt": "Unread": 0, "Total" : "Update_time": "2016-04-01 00:09:28", "lastest_content": {"type": 0, "data": {"text": "\u611a\u4eba\u8282\u6765\ U4e34\u4e4b\u9645\uff0c\u5fc3\u4e2d\u7684\u5c0f\u6076\u9b54\u6b63\u5728\u9a9a\u52a8\u3002\u6613\u76f4\u64ad\ u611a\u4eba\u8282\u65e0\u654c\u5927\u738b\u4e89\u9738\u96c6\u7ed3\u53f7\u4e5f\u501f\u52bf\u90aA\u6076\u5439\u54cd\uff01\u770b\u5404\u5927\u5bb6\u5982\u4f55\u5927\u65bd\u8ff7\u9b42\u9635\uff0c\u6597\u5fd7\ U6597\u52c7\uff0c\u620e\u9a6c\u800c\u5f52\u3002\u201c\u611a\u4eba\u5927\u738b\u201d\u3001\u201c\u8303\u4e8c\ U5927\u738b\u201d\u7a76\u7adf\u82b1\u843d\u8c01\u5bb6\u5462\uff1f\u54b1\u4eec\u62ed\u76ee\u4ee5\u5f85\uff01 "}} }]}}</span>
The generated bean
<span style= "FONT-SIZE:14PX;" >import Java.util.list;public class Messagegroupentity {/** * Retval:ok * reterr: * retinfo: {"Coun T ": 2," groups ": [{" GroupID ": 1," title ":" New Friend ", *" icon ":" Http://aliimg.yizhibo.tv/online/message/2f/74/hi.png "," type " ":" 1 "," readcnt ":" Unread ": 2," total ": +," update_time ":" 2016-04-05 09:11:09 "," lastest_content ": {" type ": 2, *" Da Ta ": {" name ":" 16837286 "," nickname ":" Lotus "," gender ":" Female "," signature ":" "," VIP ":" 0 ", *" Logourl ":"/http " Aliimg.yizhibo.tv/online/user/2c/17/[email protected]_100w_90q_0e_1c "}}} *, {" GroupID ": 0," title ":" Easy Live small secretary "," Icon ":" Http://aliimg.yizhibo.tv/online/message/07/fd/Secretary.png "," type ": 0," readcnt ":" Unread ": 0," Total " : "Update_time": "2016-04-01 00:09:28", * "Lastest_content": {"type": 0, "data": {"text": "April Fool's Day, the heart of the little demon is in turmoil." Easy Live April Fools Invincible King Hegemony assembly number also occasion evil blows! * See how everyone big mihunzhen, fighting courage, rongma and return. \u201c fool King \u201d, \u201c Hanji King \u201d who is the flower of the house? Let's wait and see! "}}}]} */private String retval; Private String RETerr; /** * count:2 * groups: [{"GroupID": 1, "title": "New Friend", * "icon": "Http://aliimg.yizhibo.tv/online/message/2f/7 4/hi.png "," type ":" 1 "," readcnt ":" Unread ": 2," total ": +," update_time ":" 2016-04-05 09:11:09 ", *" lastest_content ": {" type ": 2," data ": {" name ":" 16837286 "," nickname ":" Lotus "," gender ":" Female ", *" signature ":" "," VIP ":" 0 "," Logourl ":" Http://aliimg.yizhibo.tv/online/user/2c/17/[email protected]_100w_90q_0e_1c "}}}, * {" GroupID ": 0," title ":" Easy Live Small secretary "," icon ":" Http://aliimg.yizhibo.tv/online/message/07/fd/Secretary.png ", *" type ": 0," readcnt ":" Unread ": 0 , "Total": "Update_time": "2016-04-01 00:09:28", "lastest_content": * {"type": 0, "data": {"text": "April Fool's Day comes, the heart of the little demon is in turmoil." Easy Live April Fools Invincible King Hegemony assembly number also occasion evil blows! See how everyone big mihunzhen, fighting courage, rongma and return. * \u201c fool King \u201d, \u201c Hanji King \u201d who is the flower of the house? Let's wait and see! '}}] */private retinfoentity retinfo; public void Setretval (String retval) {this.retval = retval; } public void Setreterr (String reterr) {This.reterr= Reterr; } public void Setretinfo (Retinfoentity retinfo) {this.retinfo = Retinfo; } public String Getretval () {return retval; } public String Getreterr () {return reterr; } public retinfoentity Getretinfo () {return retinfo; } public static class Retinfoentity {private int count; /** * groupid:1 * Title: New friend * Icon:http://aliimg.yizhibo.tv/online/message/2f/74/hi.png * Type:1 * readcnt:67 * unread:2 * total:19 * update_time:2016-04-05 09:11:0 9 * lastest_content: {"type": 2, "data": {"name": "16837286", "nickname": "Lotus", "gender": "Female", "signature": "", "VIP": " 0 "," Logourl ":" Http://aliimg.yizhibo.tv/online/user/2c/17/[email protected]_100w_90q_0e_1c "}} */privat e list<groupsentity> groups; public void SetCount (int count) {This.count = count; } public void Setgroups (LIST<GROupsentity> groups) {this.groups = groups; } public int GetCount () {return count; } public list<groupsentity> GetGroups () {return groups; } public static class Groupsentity {private int groupid; Private String title; Private String icon; Private String type; private int readcnt; private int unread; private int total; Private String Update_time; /** * Type:2 * data: {"name": "16837286", "nickname": "Lotus", "gender": "Female", "signature": "", "VIP": "0", "Logourl": "http://aliimg.yizhibo.tv/online/user/2c/17/[email protected]_100w_90q_0e_1c"} */ Private Lastestcontententity lastest_content; public void setgroupid (int groupid) {this.groupid = GroupID; } public void Settitle (String title) {This.title = title; } public void SetIcon (String icon) {This.icon = icon; The public void SetType (String type) {this.type = type; } public void setreadcnt (int readcnt) {this.readcnt = readcnt; } public void Setunread (int unread) {this.unread = unread; } public void Settotal (int total) {this.total = total; } public void Setupdate_time (String update_time) {this.update_time = Update_time; } public void Setlastest_content (Lastestcontententity lastest_content) {this.lastest_content = Lastest_content; } public int Getgroupid () {return groupid; } public String GetTitle () {return title; } public String GetIcon () {return icon; } public String GetType () {return type; } public int getreadcnt () {return readcnt; } public int Getunread () {return unread; } public int Gettotal () {return total; } public String Getupdate_time () {return update_time; } public lastestcontententity Getlastest_content () {return lastest_content; } public static class Lastestcontententity {private int type; /** * name:16837286 * Nickname: Lotus * Gender:female * Signature: * vip:0 * logourl:http://aliimg.yizhibo.tv/online/user/2c/17/[email p ROTECTED]_100W_90Q_0E_1C */private dataentity data; public void SetType (int typE) {this.type = type; } public void SetData (dataentity data) {this.data = data; } public int GetType () {return type; } public dataentity GetData () {return data; } public static class Dataentity {private String name; Private String nickname; Private String gender; Private String signature; Private String VIP; Private String Logourl; public void SetName (String name) {this.name = name; } public void Setnickname (String nickname) {this.nickname = nickname; } public void Setgender (String gender) {This.gender = gender; } public void Setsignature (String signature) {This.signature = signature; } public void Setvip (String vip) {this.vip = VIP; } public void Setlogourl (String logourl) {this.logourl = Logourl; } public String GetName () {return name; } public String Getnickname () {return nickname; } public String Getgender () {return gender; } public String Getsignature () {return signature; } public String Getvip () {return VIP; } public String Getlogourl () {RETurn Logourl; }}}}}}</span>
This is probably the process, I hope to help you.
Welcome everyone to join my QQ group:454430053
Android Studio Plugin Gsonformat (automatically generated JavaBean)