记录GsonFormat插件的使用

来源:互联网 发布:海珠区大塘村网络被剪 编辑:程序博客网 时间:2024/06/06 02:06

. 插件功能:
根据json格式的字符串,在android studio或者Intellij IDEA平台上自动生成对应的类(对象or实体)

. 使用步骤(android studio):
1.安装GsonFormat插件
File -> Settings ->Plugins -> Browse Repositories -> 搜索框里搜索GsonFormat -> 点击安装 -> 重启android studio
2.new一个类(类名自定义如bean)
3.打开GsonFormat的对话框
Code -> Generate -> GsonFormat (可以自定义快捷键,然后用快捷键打开,自定义为Alt + a)
4.将json字符串复制到对话框里,-> Format -> OK
5.自动生成对应的类
.效果如下所示:
json 数据

 {      "_id": "58de5542421aa969fd8a3df9",       "createdAt": "2017-03-31T21:10:26.504Z",       "desc": "\u7b2c\u4e09\u65b9SDK\u96c6\u6210\u5e93(\u6388\u6743/\u5206\u4eab/\u652f\u4ed8)",       "publishedAt": "2017-04-13T11:36:04.435Z",       "source": "web",       "type": "Android",       "url": "https://github.com/czy1121/sdk3rd",       "used": true,       "who": "ezy"    }

自动生成的类

public class Bean {    /**     * _id : 58de5542421aa969fd8a3df9     * createdAt : 2017-03-31T21:10:26.504Z     * desc : 第三方SDK集成库(授权/分享/支付)     * publishedAt : 2017-04-13T11:36:04.435Z     * source : web     * type : Android     * url : https://github.com/czy1121/sdk3rd     * used : true     * who : ezy     */    private String _id;    private String createdAt;    private String desc;    private String publishedAt;    private String source;    private String type;    private String url;    private boolean used;    private String who;    public String get_id() {        return _id;    }    public void set_id(String _id) {        this._id = _id;    }    public String getCreatedAt() {        return createdAt;    }    public void setCreatedAt(String createdAt) {        this.createdAt = createdAt;    }    public String getDesc() {        return desc;    }    public void setDesc(String desc) {        this.desc = desc;    }    public String getPublishedAt() {        return publishedAt;    }    public void setPublishedAt(String publishedAt) {        this.publishedAt = publishedAt;    }    public String getSource() {        return source;    }    public void setSource(String source) {        this.source = source;    }    public String getType() {        return type;    }    public void setType(String type) {        this.type = type;    }    public String getUrl() {        return url;    }    public void setUrl(String url) {        this.url = url;    }    public boolean isUsed() {        return used;    }    public void setUsed(boolean used) {        this.used = used;    }    public String getWho() {        return who;    }    public void setWho(String who) {        this.who = who;    }}
0 0