Android Studio - 安装插件GsonFormat

tech2023-01-13  117

一、Settings

二、搜索插件

三、使用(下载好插件之后,重启Android Studio)

Alt + Inset(快捷键1)

Alt + s(快捷键2)

Json数据 { "data":{ "count":5, "items":[ { "id":45, "title":"小麦" }, { "id":134, "title":"大米" }, { "id":115, "title":"小米" }, { "id":15, "title":"苹果" }, { "id":68, "title":"三只松鼠" } ] }, "rs_code":"1000", "rs_msg":"success" }

把Json数据复制粘贴进去(点击format进行格式化)

格式化后

生成代码

/** * data : {"count":5,"items":[{"id":45,"title":"小麦"},{"id":134,"title":"大米"},{"id":115,"title":"小米"},{"id":15,"title":"苹果"},{"id":68,"title":"三只松鼠"}]} * rs_code : 1000 * rs_msg : success */ private DataBean data; private String rs_code; private String rs_msg; public DataBean getData() { return data; } public void setData(DataBean data) { this.data = data; } public String getRs_code() { return rs_code; } public void setRs_code(String rs_code) { this.rs_code = rs_code; } public String getRs_msg() { return rs_msg; } public void setRs_msg(String rs_msg) { this.rs_msg = rs_msg; } public static class DataBean { /** * count : 5 * items : [{"id":45,"title":"小麦"},{"id":134,"title":"大米"},{"id":115,"title":"小米"},{"id":15,"title":"苹果"},{"id":68,"title":"三只松鼠"}] */ private int count; private List<ItemsBean> items; public int getCount() { return count; } public void setCount(int count) { this.count = count; } public List<ItemsBean> getItems() { return items; } public void setItems(List<ItemsBean> items) { this.items = items; } public static class ItemsBean { /** * id : 45 * title : 小麦 */ private int id; private String title; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } } }
最新回复(0)