Android Studio 优秀插件:GsonFormat
作为一个Android程序猿,当你看到后台给你的json数据格式时:
{
"id":123,
"url": "http://img.donever.com/aa/bb.jpg",
"width":500,
"height":500,
"likeCount":1,
"description":"嘿嘿",
"time":1234567890,
"replyCount":0,
"floorCount":0,
"likeUserCount":5,
"age":14,
"name":"jack",
"school":"beijing",
"type":1,
"sax":"boy",
"userid":1223
}
是不是要默默的创建一个类,然后一个个变量的private 一下,然后get()+set()?
如果一个json数据提供的属性20+条或者30+条呢,一个个属性去写,还要保证字母不写错,大小写也没错,是不是既浪费时间又浪费精力,那么就试试使用GsonFormat插件吧
现在学习下如何使用这个插件:
1、Android Studio 打开一个项目,点击左上角 File -->Settings... 进行设置

2、选择插件Plugins , 搜索GsonFormat ,如果你没有下载过这个插件,那么搜索框下面会显示“Nothing to show.Click Browse to....”

3、那就点击蓝色字体的 Browse 吧 ,这个时候会出现如下图的界面,我们只需要在左边选中GsonFormat 然后点击右面 绿色按钮 "Install plugin" 就可以了

4、完成了上面三个步骤,就可以使用GsonFormat插件了
怎么用呢,
(1)创建一个类文件,类名是看你需求自定义写的
(2)快捷键 alt+insert ,会出现如下选择框

(3)我们点击第一个选项,GsonFormat,就会出现一个新的框,
然后只需要将服务器给你的json数据的 格式复制进去 ,如下所示,点击Ok就可以了(注意json格式不要出错,比如不要少了每个属性后面的逗号)

(4)最后一步,出现这么一个框,这里你可以进行相应的编辑,比如吧一个属性的类型改变,或者 去掉属性前面的蓝底白勾,让类不具有某个属性

效果类:
public class People {
/**
* id : 123
* url : http://img.donever.com/aa/bb.jpg
* width : 500
* height : 500
* likeCount : 1
* description : 嘿嘿
* time : 1234567890
* replyCount : 0
* floorCount : 0
* likeUserCount : 5
* age : 14
* name : jack
* school : beijing
* type : 1
* sax : boy
* userid : 1223
*/
private int id;
private String url;
private int width;
private int height;
private int likeCount;
private String description;
private int time;
private int replyCount;
private int floorCount;
private int likeUserCount;
private int age;
private String name;
private String school;
private int type;
private String sax;
private int userid;
public static People objectFromData(String str) {
Gson gson = new Gson();
return new com.google.gson.Gson().fromJson(str, People.class);
}
public void setId(int id) {
this.id = id;
}
public void setUrl(String url) {
this.url = url;
}
public void setWidth(int width) {
this.width = width;
}
public void setHeight(int height) {
this.height = height;
}
public void setLikeCount(int likeCount) {
this.likeCount = likeCount;
}
public void setDescription(String description) {
this.description = description;
}
public void setTime(int time) {
this.time = time;
}
public void setReplyCount(int replyCount) {
this.replyCount = replyCount;
}
public void setFloorCount(int floorCount) {
this.floorCount = floorCount;
}
public void setLikeUserCount(int likeUserCount) {
this.likeUserCount = likeUserCount;
}
public void setAge(int age) {
this.age = age;
}
public void setName(String name) {
this.name = name;
}
public void setSchool(String school) {
this.school = school;
}
public void setType(int type) {
this.type = type;
}
public void setSax(String sax) {
this.sax = sax;
}
public void setUserid(int userid) {
this.userid = userid;
}
public int getId() {
return id;
}
public String getUrl() {
return url;
}
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public int getLikeCount() {
return likeCount;
}
public String getDescription() {
return description;
}
public int getTime() {
return time;
}
public int getReplyCount() {
return replyCount;
}
public int getFloorCount() {
return floorCount;
}
public int getLikeUserCount() {
return likeUserCount;
}
public int getAge() {
return age;
}
public String getName() {
return name;
}
public String getSchool() {
return school;
}
public int getType() {
return type;
}
public String getSax() {
return sax;
}
public int getUserid() {
return userid;
}
}
People
如果要使用Gson解析的话 ,即 通过Json字符串直接获取对应的类对象
public static People objectFromData(String str) {
Gson gson = new Gson();
return gson.fromJson(str, People.class);
}
记得在build.gradle 中加上
compile 'com.google.code.gson:gson:2.4'
Android Studio 优秀插件:GsonFormat的更多相关文章
- Android开发实战(十八):Android Studio 优秀插件:GsonFormat
Android Studio 优秀插件系列: Android Studio 优秀插件(一):GsonFormat Android Studio 优秀插件(二): Parcelable Code Gen ...
- Android项目实战(十九):Android Studio 优秀插件: Parcelable Code Generator
Android Studio 优秀插件系列: Android Studio 优秀插件(一):GsonFormat Android Studio 优秀插件(二): Parcelable Code Gen ...
- Android Studio安装插件GsonFormat
Android Studio菜单栏File > Settings > plugins' 这个是Android Studio搜索和安装插件的界面,下面直接上动图 : 安装结束后需要关闭重新启 ...
- Android Studio 优秀插件汇总
第一部分 插件的介绍 Google 在2013年5月的I/O开发者大会推出了基于IntelliJ IDEA java ide上的Android Studio.AndroidStudio是一个功能齐全的 ...
- 拿走不谢!22 个 Android Studio 优秀插件汇总
Google 在2013年5月的I/O开发者大会推出了基于IntelliJ IDEA java ide上的Android Studio.AndroidStudio是一个功能齐全的开发工具,还提供了第三 ...
- Android Studio 优秀插件: Parcelable Code Generator
这里假设我们已经会使用 Parcelable 序列化一个对象了~~ 那么大家会发现 Parcelable 使用起来有些复杂,因为我们要自己复写 几个方法,而且当类的属性比较多的时候,我们就会难受了,又 ...
- Android Studio优秀插件汇总
- [Android Studio]SQLScout插件安装破解
以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/5972138.html [Android Studio]SQLS ...
- Android Studio 工具插件
1.Android Studio 翻译插件,可以将英文翻译为中文. https://github.com/Skykai521/ECTranslation 2.Android Studio之Androi ...
随机推荐
- 多级树的深度遍历与广度遍历(Java实现)
目录 多级树的深度遍历与广度遍历 节点模型 深度优先遍历 广度优先遍历 多级树的深度遍历与广度遍历 深度优先遍历与广度优先遍历其实是属于图算法的一种,多级树可以看做是一种特殊的图,所以多级数的深/广遍 ...
- 【Nginx】四层负载均衡配置
一.概述 二.配置 2.1 环境准备 2.2 安装及配置 1).下载Nginx 2).下载nginx_tcp_proxy_module 插件 3).编译Nginx 4).修改Nginx.conf配置文 ...
- Python编程书籍高清PDF免费下载
场景 CSDN: https://blog.csdn.net/badao_liumang_qizhi 博客园: https://www.cnblogs.com/badaoliumangqizhi/ 哔 ...
- Winform中使用ZedGraph实现曲线图中字体去掉边框
场景 Winforn中设置ZedGraph曲线图的属性.坐标轴属性.刻度属性: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/10 ...
- Hadoop学习笔记之HBase Shell语法练习
Hadoop学习笔记之HBase Shell语法练习 作者:hugengyong 下面我们看看HBase Shell的一些基本操作命令,我列出了几个常用的HBase Shell命令,如下: 名称 命令 ...
- linux切换jdk
一.安装openjdk yum search openjdk yum install java-1.8.0-openjdk-devel-debug.x86_64 二.查询java版本 alternat ...
- Falsk中的Request、Response
Flask 中的Response 1.HTTPResponse('helloword') "helloword" from flask import Flask # 实例化Flas ...
- [C++]类的设计(2)——拷贝控制(阻止拷贝)
1.阻止拷贝的原因:对于某些类来说,拷贝构造函数和拷贝赋值运算符没有意义.举例:iostream类阻止了拷贝,以避免多个对象写入或者读取相同的IO缓冲. 2.阻止拷贝的方法有两个:新标准中可以将成 ...
- 【linux】【maven】maven及maven私服安装
前言 系统环境:Centos7.jdk1.8 私服是一种特殊的远程仓库,它是架设在局域网内的仓库服务,私服代理广域网上的远程仓库,供局域网内的用户使用.当Maven需要下载构件的时候,它从私服请求,如 ...
- asp.net core IdentityServer4 实现 Client credentials(客户端凭证)
前言 OAuth 2.0默认四种授权模式(GrantType) 授权码模式(authorization_code) 简化模式(implicit) 密码模式(resource owner passwor ...