andorid studio之GsonFormat插件的使用

每次创建实体bean的时候,都要手动去建立,特别是字段多的时候,需要一个个去建立。很耗时,
最近在研究Retrofit框架的时候发现了一个很好用的插件,自己迫不及待的试用了下感觉效果还不错,来分享一下。

添加方法:
Setting->plugins->搜索GsonFormat->下载
下载完成后会提升你重启android studio,照做就行了

使用方法:

随便建个空类,按alt+insert,选择第一个GsonFormat,然后提示你输入内容,把要解析的字段拷贝进去。
需要修改类型的直接修改,完成后点确定。稍等几秒就行了,具体操作和效果看下图。

这里写图片描述

实例json代码:


{
  "scope": "read", 
  "expires_in": 43199, 
  "token_type": "bearer", 
  "refresh_token": "513bc93c-3a97-4847-bcfd-f0b58a90590f", 
  "access_token": "ca70fd73-8d63-4f82-a82f-f62e90fe344f"
}

自动生成后的代码:

public class Test {

    /**
     * scope : read
     * expires_in : 43199
     * token_type : bearer
     * refresh_token : 513bc93c-3a97-4847-bcfd-f0b58a90590f
     * access_token : ca70fd73-8d63-4f82-a82f-f62e90fe344f
     */

    private String scope;
    private int expires_in;
    private String token_type;
    private String refresh_token;
    private String access_token;

    public String getScope() {
        return scope;
    }

    public void setScope(String scope) {
        this.scope = scope;
    }

    public int getExpires_in() {
        return expires_in;
    }

    public void setExpires_in(int expires_in) {
        this.expires_in = expires_in;
    }

    public String getToken_type() {
        return token_type;
    }

    public void setToken_type(String token_type) {
        this.token_type = token_type;
    }

    public String getRefresh_token() {
        return refresh_token;
    }

    public void setRefresh_token(String refresh_token) {
        this.refresh_token = refresh_token;
    }

    public String getAccess_token() {
        return access_token;
    }

    public void setAccess_token(String access_token) {
        this.access_token = access_token;
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值