Android studio 外掛程式之 GsonFormat (自己主動產生javabean)

來源:互聯網
上載者:User

標籤:line   nic   vip   logo   lan   推薦   upd   end   name   

概述

相信大家在做開發的過程中都寫過非常多的javabean ,非常多情況下 都是一個列表資料就是一個單獨的javabean。假設大家自己敲的話費時費力 還非常easy敲錯。

今天給大家推薦一個外掛程式 GsonFormat  這個外掛程式就是能夠讓我們直接將服務端返回的json轉化為實體類。Android studio和idea都有, eclipse我沒有試過。

大家能夠找找有沒有。


操作步驟第一步  下載外掛程式

下載外掛程式的過程我前面有一篇部落格已經有具體步驟  Android Studio外掛程式之sexy editor(設定AS背景) 大家 僅僅須要將那篇部落格中介紹的外掛程式名稱換成GsonFormat

依照那個步驟下載好 外掛程式。記得下載安裝好後要重新啟動哦。

第二步  自己主動產生bean

以下我們介紹怎麼通過這個外掛程式將服務端返回的json自己主動產生javabean


首先  我們要建一個空的java類,然後 在空白出點擊滑鼠右鍵  選擇 Generate... 假設你已經安裝成功好外掛程式會彈出以下這個框



選擇GsonFormat會彈出以下這個框



將服務端接返回的json 粘貼到這個裡面 點擊ok



 粘貼完畢後 點擊ok會彈出例如以所看到的的選擇 欄位介面




這個介面是讓你自己選擇 保留哪些欄位。可能有的欄位不須要 就把前面的對勾去掉就能夠了。最後點擊ok。大功告成。


貼上json字串和自己主動產生出的bean代碼.

json字串

<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":67,"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":86,"unread":0,"total":86,"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>

產生的bean


<span style="font-size:14px;">import java.util.List;public class MessageGroupEntity {    /**     * retval : ok     * reterr :     * retinfo : {"count":2,"groups":[{"groupid":1,"title":"新朋友",     * "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:09","lastest_content":{"type":2,     * "data":{"name":"16837286","nickname":"阿蓮","gender":"female","signature":"","vip":"0",     * "logourl":"http://aliimg.yizhibo.tv/online/user/2c/17/[email protected]_100w_90Q_0e_1c"}}}     * ,{"groupid":0,"title":"易直播小秘書","icon":"http://aliimg.yizhibo.tv/online/message/07/fd/Secretary.png","type":0,"readcnt":86,     * "unread":0,"total":86,"update_time":"2016-04-01 00:09:28",     * "lastest_content":{"type":0,"data":{"text":"愚人節來臨之際。心中的小惡魔正在騷動。易直播愚人節無敵大王爭霸集結號也借勢邪惡吹響!     * 看各大家怎樣大施迷魂陣,鬥志鬥勇,戎馬而歸。

\u201c愚人大王\u201d、\u201c範二大王\u201d到底花落誰家呢?咱們拭目以待!"}}}]} */ private String retval; private String reterr; /** * count : 2 * groups : [{"groupid":1,"title":"新朋友", * "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:09", * "lastest_content":{"type":2,"data":{"name":"16837286","nickname":"阿蓮","gender":"female", * "signature":"","vip":"0","logourl":"http://aliimg.yizhibo.tv/online/user/2c/17/[email protected]_100w_90Q_0e_1c"}}}, * {"groupid":0,"title":"易直播小秘書","icon":"http://aliimg.yizhibo.tv/online/message/07/fd/Secretary.png", * "type":0,"readcnt":86,"unread":0,"total":86,"update_time":"2016-04-01 00:09:28","lastest_content": * {"type":0,"data":{"text":"愚人節來臨之際,心中的小惡魔正在騷動。易直播愚人節無敵大王爭霸集結號也借勢邪惡吹響!看各大家怎樣大施迷魂陣。鬥志鬥勇。戎馬而歸。 * \u201c愚人大王\u201d、\u201c範二大王\u201d到底花落誰家呢?咱們拭目以待!"}}}] */ 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 : 新朋友 * 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:09 * lastest_content : {"type":2,"data":{"name":"16837286","nickname":"阿蓮","gender":"female","signature":"","vip":"0","logourl":"http://aliimg.yizhibo.tv/online/user/2c/17/[email protected]_100w_90Q_0e_1c"}} */ private 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":"阿蓮","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; } 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 : 阿蓮 * gender : female * signature : * vip : 0 * logourl : http://aliimg.yizhibo.tv/online/user/2c/17/[email protected]_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>




 大概流程就是這樣,希望對大家有所協助。

 

歡迎大家增加我的qq 群:454430053






Android studio 外掛程式之 GsonFormat (自己主動產生javabean)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.