Overview
I believe that everyone in the development process has written a lot of javabean, very many cases are a list of data is a separate javabean. Let's say it's time-consuming and easy to knock the wrong way.
Today we recommend a plugin Gsonformat this plugin is the ability to directly convert the JSON returned from the server to the entity class. Both Android studio and idea have, eclipse I have not tried.
Can we look for any.
Operation StepsFirst step Download plugin
The process of downloading the plugin I have a blog in front of the specific steps of the Android Studio plugin sexy editor (set as background) you 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 the download after installation.
The second step is to generate the bean yourself
Below we describe how to use this plugin to return the service to the JSON itself actively generated JavaBean
First we want to build an empty Java class, and then right-click on the blank left mouse button to select Generate ... Assuming you have successfully installed the plugin will pop up the following box.
Selecting Gsonformat will bring up the following box
Paste the JSON returned by the service back into this and click OK.
Clicking OK after pasting will pop up for example the selection field interface that you see
This interface is for you to choose which fields to keep. There may be fields that do not need to be removed from the previous tick. Finally click OK. Done.
Paste the JSON string and the bean code that you actively generate.
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": 86, " Update_time ":" 2016-04-01 00:09:28 ", *" Lastest_content ": {" type ": 0," data ": {" text ":" April Fool's Day comes. " The little demon in my heart is in turmoil. Easy Live April Fools Invincible King Hegemony assembly number also occasion evil blows! * See how all the big mihunzhen, fighting courage, rongma and return.\u201c fool King \u201d, \u201c Hanji King \u201d in the end who the flowers fall? 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 each of us big Shi Mihunzhen. Fight bravely. Rongma and return. * \u201c fool King \u201d, \u201c Hanji King \u201d in the end who the flowers fall? 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 increase my QQ group:454430053
Android Studio Plugin Gsonformat (self-generated javabean)