每次创建实体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;
}
}