gsonformat安装

插件地址:https://plugins.jetbrains.com/idea/plugin/7654-gsonformat

IntelliJ IDEA 如何通过GsonFormat插件将JSONObject格式的String 解析成实体。
File->Settings->Plugins—>查找所需插件—>Install
或者
File->Settings->Plugins—>Install plug from disk —>选择下载好的插件安装

一般插件安装之后重启IDEA即可生效。

下面详细安装图文:

先到setting里面,然后通过搜索Plugins

然后插件栏搜索GsonFormat。

安装即可。

安装完,需要重启一下idea。

 

通过json

 

1

2

3

4

5

6

7

8

9

{

"animals":{

"dog":[

{"name":"Rufus","breed":"labrador","count":1,"twoFeet":false},

{"name":"Marty","breed":"whippet","count":1,"twoFeet":false}

],

"cat":{"name":"Matilda"}

}

}

 

自定义个javaBean(无任何内容,就一个空的类)

复制你要解析的json

然后alt+insert弹出如下界面 或者使用快捷键 alt+s

通过快捷键调出该插件

格式化json

可以设置

ok即可生成实体类

配置生成名

生成如下:

 
  1. package com.yuanding.entity;

  2.  
  3. import java.util.List;

  4.  
  5. /**

  6. * Created by diyvc on 2017/3/13.

  7. */

  8. public class TestClass {

  9.  
  10.  
  11. /**

  12. * animals : {"dog":[{"name":"Rufus","breed":"labrador","count":1,"twoFeet":false},{"name":"Marty","breed":"whippet","count":1,"twoFeet":false}],"cat":{"name":"Matilda"}}

  13. */

  14.  
  15. private AnimalsBean animals;

  16.  
  17. public AnimalsBean getAnimals() {

  18. return animals;

  19. }

  20.  
  21. public void setAnimals(AnimalsBean animals) {

  22. this.animals = animals;

  23. }

  24.  
  25. public static class AnimalsBean {

  26. /**

  27. * dog : [{"name":"Rufus","breed":"labrador","count":1,"twoFeet":false},{"name":"Marty","breed":"whippet","count":1,"twoFeet":false}]

  28. * cat : {"name":"Matilda"}

  29. */

  30.  
  31. private CatBean cat;

  32. private List<DogBean> dog;

  33.  
  34. public CatBean getCat() {

  35. return cat;

  36. }

  37.  
  38. public void setCat(CatBean cat) {

  39. this.cat = cat;

  40. }

  41.  
  42. public List<DogBean> getDog() {

  43. return dog;

  44. }

  45.  
  46. public void setDog(List<DogBean> dog) {

  47. this.dog = dog;

  48. }

  49.  
  50. public static class CatBean {

  51. /**

  52. * name : Matilda

  53. */

  54.  
  55. private String name;

  56.  
  57. public String getName() {

  58. return name;

  59. }

  60.  
  61. public void setName(String name) {

  62. this.name = name;

  63. }

  64. }

  65.  
  66. public static class DogBean {

  67. /**

  68. * name : Rufus

  69. * breed : labrador

  70. * count : 1

  71. * twoFeet : false

  72. */

  73.  
  74. private String name;

  75. private String breed;

  76. private int count;

  77. private boolean twoFeet;

  78.  
  79. public String getName() {

  80. return name;

  81. }

  82.  
  83. public void setName(String name) {

  84. this.name = name;

  85. }

  86.  
  87. public String getBreed() {

  88. return breed;

  89. }

  90.  
  91. public void setBreed(String breed) {

  92. this.breed = breed;

  93. }

  94.  
  95. public int getCount() {

  96. return count;

  97. }

  98.  
  99. public void setCount(int count) {

  100. this.count = count;

  101. }

  102.  
  103. public boolean isTwoFeet() {

  104. return twoFeet;

  105. }

  106.  
  107. public void setTwoFeet(boolean twoFeet) {

  108. this.twoFeet = twoFeet;

  109. }

  110. }

  111. }

  112. }

 

需要好看的话,自己配置一下。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值