简介

GsonFormat是一款根据Gson库使用的要求,将JSONObject格式的String 解析成实体的插件。这是一个根据JSONObject格式的字符串,自动生成实体类参数,本插件只适用 android studio和 Intellij IDEA 工具。**

安装

FileSettingsPluginsBrowse Repositories

  • 搜索关键字: GsonFormat
  • 安装:点击 install

image.png

实践

  • 测试JSON

    1. {"test": {"tools": [{
    2. "name": "GsonFormat",
    3. "varsion": "1.0.0"
    4. }]}}
  • 新建一个类

  • 按键 Alt + instell

image.png

  • 再次按 Alt + S

image.png

  • 根据实际情况调整字段的类型、名称等

image.png

  • 生成结果

    1. /**
    2. * test : {"tools":[{"name":"GsonFormat","varsion":"1.0.0"}]}
    3. */
    4. private TestBean test;
    5. public TestBean getTest() {
    6. return test;
    7. }
    8. public void setTest(TestBean test) {
    9. this.test = test;
    10. }
    11. public static class TestBean {
    12. private List<ToolsBean> tools;
    13. public List<ToolsBean> getTools() {
    14. return tools;
    15. }
    16. public void setTools(List<ToolsBean> tools) {
    17. this.tools = tools;
    18. }
    19. public static class ToolsBean {
    20. /**
    21. * name : GsonFormat
    22. * varsion : 1.0.0
    23. */
    24. private String name;
    25. private String varsion;
    26. public String getName() {
    27. return name;
    28. }
    29. public void setName(String name) {
    30. this.name = name;
    31. }
    32. public String getVarsion() {
    33. return varsion;
    34. }
    35. public void setVarsion(String varsion) {
    36. this.varsion = varsion;
    37. }
    38. }
    39. }