├── Json
├── .gitignore
├── build.gradle
└── src
│ └── main
│ └── java
│ └── com
│ └── yanxuwen
│ └── json
│ └── JsonUtils.java
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── README.md
├── gradlew.bat
├── src
└── main
│ └── java
│ ├── Main.java
│ └── bean
│ ├── DataBean.java
│ └── Bean.java
└── gradlew
/Json/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':json'
2 | rootProject.name = 'Json'
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanxuwen/Json/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/Json/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'java'
3 | }
4 |
5 | group 'Json'
6 | version '1.0-SNAPSHOT'
7 |
8 | sourceCompatibility = 1.8
9 |
10 | repositories {
11 | mavenCentral()
12 | }
13 |
14 | dependencies {
15 | testCompile group: 'junit', name: 'junit', version: '4.12'
16 | compile 'com.alibaba:fastjson:1.2.58'
17 | }
18 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 一直觉得java在Json解析上不够优雅,不够简洁。传统的JSONObject的解析,真的,解析个东西简直要疯掉。
2 | 后面出了个FastJson跟Gson,虽然很好用,但是有时候也是很烦,
3 | 比如:我要解析一个很深沉的字符串。其他字符串我不要。
4 | 
5 | 如上图:我要解析title里面的文字,其他不需要,【当然里,只需要一个一个字段,其他不需要 这种需求是真的少见】
6 | 如果我们使用FastJson跟Gson第一步肯定要先建一个类,然后json转化成实体类
7 | 然后取的时候还要一直get ,取名字取短的话还好,要是名字很长,看起来真心难受。
8 | ~~~
9 | bean.getBody().getData().get(0).getTitle()
10 | ~~~
11 | 这种情况下,我们就需要用到一个简洁的解析 如:
12 | ~~~
13 | String title = JsonUtils.parse(json,String.class,"body","data",0,"title");
14 | ~~~
15 | 使用这种方式的话,我们不需要创建类,也不担心你json串是否符合你要的字段,哪层字段没有,就直接返回 “”,
16 | $\color{red}{支持常用类型,跟实体类类型}$
17 |
18 | 当然咯,转换实体类还是非常还好用的,我们要转换某层下面的实体类也非常方便,只需要改第二个参数为实体类类型就即可,下面给一个全部的实例:
19 | ~~~
20 | // 1、解析body -> data -> 0
21 | String data_0 = JsonUtils.parse(json,String.class,"body","data",0);
22 | System.out.println("data -> 0: " + data_0);
23 |
24 | // 2、解析body -> data -> 0 -> title
25 | String title = JsonUtils.parse(json,String.class,"body","data",0,"title");
26 | System.out.println("title: " + title);
27 |
28 | // 3、解析body -> data -> 0 转化为实体类
29 | DataBean data = JsonUtils.parse(json, DataBean.class,"body","data",0);
30 | //用DataBean去取title 看是否正确
31 | System.out.println("DataBean -> title: " + data.getTitle());
32 |
33 | // 4、直接将整串json转换为实体类
34 | Bean bean = JsonUtils.parse(json, Bean.class);
35 | //用Bean去取title 看是否正确
36 | System.out.println("Bean -> title: " + bean.getBody().getData().get(0).getTitle());
37 |
38 | // 5、实体类转换为json,用的是FastJson的用法
39 | String jsonStr = JsonUtils.toString(bean);
40 | System.out.println(jsonStr);
41 | ~~~
42 | ### 使用gradle添加依赖
43 | ~~~
44 | compile 'com.yanxuwen:json:1.0.0'
45 | ~~~
46 | ### 使用pom添加依赖
47 | ~~~
48 |
49 | com.yanxuwen
50 | json
51 | 1.0.0
52 |
53 | ~~~
54 |
55 | ### 博客地址 [点击跳转](https://www.jianshu.com/p/95946a15cae1)
56 | ### 如果你喜欢就去 github 帮我star下,非常感谢o(∩_∩)o~~~
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/Json/src/main/java/com/yanxuwen/json/JsonUtils.java:
--------------------------------------------------------------------------------
1 | package com.yanxuwen.json;
2 | import com.alibaba.fastjson.JSON;
3 | import com.alibaba.fastjson.JSONArray;
4 | import com.alibaba.fastjson.JSONObject;
5 |
6 | public class JsonUtils {
7 |
8 | /**
9 | * @param json json串
10 | * @param clazz 返回类型
11 | * @param str
12 | * @return
13 | * @param
14 | */
15 | public static T parse(String json,Class clazz , Object... str) {
16 | try {
17 | JSONObject jsonObject = null;
18 | JSONArray jsonArray = null;
19 | Object o = JSON.parse(json);
20 | if (o instanceof JSONObject){
21 | jsonObject = (JSONObject)o;
22 | } else if (o instanceof JSONArray){
23 | jsonArray = (JSONArray)o;
24 | } else {
25 | return parseObject(json, clazz);
26 | }
27 | if (str == null || str.equals("") || (jsonObject == null && jsonArray == null)) {
28 | return parseObject(json, clazz);
29 | }
30 | for (int i = 0; i < str.length; i++) {
31 | if (str[i] instanceof String) {
32 | Object object = jsonObject.get(str[i]);
33 | if (object instanceof JSONObject ){
34 | jsonObject = (JSONObject)object;
35 | } else if (object instanceof JSONArray){
36 | jsonArray = (JSONArray)object;
37 | } else {
38 | if (i == str.length -1 ){//最后一层,直接解析
39 | return parseObject(String.valueOf(object), clazz);
40 | } else {//中间层获取失败
41 | return parseObject("", clazz);
42 | }
43 | }
44 | } else if (str[i] instanceof Integer || str[i] instanceof Long) {
45 | if (jsonArray == null){
46 | return parseObject(String.valueOf(jsonObject.toString()), clazz);
47 | }
48 | Object object = jsonArray.get((int)str[i]);
49 | if (object instanceof JSONObject){
50 | jsonObject = (JSONObject)object;
51 | } else {
52 | return parseObject(String.valueOf(object), clazz);
53 | }
54 | } else {
55 | return parseObject(jsonObject.toString(), clazz);
56 | }
57 | }
58 | return parseObject(jsonObject.toString(), clazz);
59 | } catch (Exception e) {
60 | return null;
61 | }
62 |
63 | }
64 | private static T parseObject (String text, Class clazz){
65 | try {
66 | T result = JSONObject.parseObject(text, clazz);
67 | if (result == null){
68 | text = null;
69 | throw new NullPointerException(""); //直接手动抛出异常
70 | }
71 | return result;
72 | } catch (Exception e){
73 | Object o = null;
74 | if (clazz.equals(String.class)){
75 | return (T) (text == null ? "" : text);
76 | } else if (clazz.equals(Integer.class)){
77 | o = Integer.parseInt(text == null ? "0" : text);
78 | return (T) o;
79 | } else if (clazz.equals(Long.class)){
80 | o = Long.parseLong(text == null ? "0" : text);
81 | return (T) o;
82 | } else if (clazz.equals(Boolean.class)){
83 | o = Boolean.parseBoolean(text == null ? "false" : text);
84 | return (T) o;
85 | } else if (clazz.equals(Double.class)){
86 | o = Double.parseDouble(text == null ? "0" : text);
87 | return (T) o;
88 | } else if (clazz.equals(Float.class)){
89 | o = Float.parseFloat(text == null ? "0" : text);
90 | return (T) o;
91 | } else {
92 | return null;
93 | }
94 | }
95 | }
96 |
97 | public static String toString(Object object) {
98 | return JSONObject.toJSONString(object);
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/src/main/java/Main.java:
--------------------------------------------------------------------------------
1 | import bean.Bean;
2 | import bean.DataBean;
3 | import com.yanxuwen.json.JsonUtils;
4 |
5 | public class Main {
6 |
7 | public static void main(String[] args) {
8 | // 1、解析body -> data -> 0
9 | String data_0 = JsonUtils.parse(json,String.class,"body","data",0);
10 | System.out.println("data -> 0: " + data_0);
11 |
12 | // 2、解析body -> data -> 0 -> title
13 | String title = JsonUtils.parse(json,String.class,"body","data",0,"title");
14 | System.out.println("title: " + title);
15 |
16 | // 3、解析body -> data -> 0 转化为实体类
17 | DataBean data = JsonUtils.parse(json, DataBean.class,"body","data",0);
18 | //用DataBean去取title 看是否正确
19 | System.out.println("DataBean -> title: " + data.getTitle());
20 |
21 | // 4、直接将整串json转换为实体类
22 | Bean bean = JsonUtils.parse(json, Bean.class);
23 | //用Bean去取title 看是否正确
24 | System.out.println("Bean -> title: " + bean.getBody().getData().get(0).getTitle());
25 |
26 | // 5、实体类转换为json,用的是FastJson的用法
27 | String jsonStr = JsonUtils.toString(bean);
28 | System.out.println(jsonStr);
29 | }
30 |
31 |
32 |
33 | static String json = "{\n" +
34 | "\t\"code\": 10000,\n" +
35 | "\t\"message\": \"成功\",\n" +
36 | "\t\"body\": {\n" +
37 | "\t\t\"data\": [{\n" +
38 | "\t\t\t\"id\": 47,\n" +
39 | "\t\t\t\"type\": 2,\n" +
40 | "\t\t\t\"title\": \"回归版块测试\",\n" +
41 | "\t\t\t\"image\": \"http://ztjy-img-dev.szytest.com/ztnew/ad/img/2018/09/28/1538124681903616.png\",\n" +
42 | "\t\t\t\"imgWidth\": 74,\n" +
43 | "\t\t\t\"imgHeight\": 71,\n" +
44 | "\t\t\t\"number\": 1,\n" +
45 | "\t\t\t\"titleType\": 0,\n" +
46 | "\t\t\t\"isMainPush\": 0,\n" +
47 | "\t\t\t\"isMore\": 1,\n" +
48 | "\t\t\t\"contentList\": [{\n" +
49 | "\t\t\t\t\"contentType\": 26,\n" +
50 | "\t\t\t\t\"contentId\": \"1017\",\n" +
51 | "\t\t\t\t\"image\": \"http://ztjy-img-dev.szytest.com/ztnew/ad/img/2019/01/16/1547630094383987.png\",\n" +
52 | "\t\t\t\t\"title\": \"小五新增专题001\",\n" +
53 | "\t\t\t\t\"desc\": \"\",\n" +
54 | "\t\t\t\t\"isMainPush\": 0,\n" +
55 | "\t\t\t\t\"beginTime\": 1547630051000,\n" +
56 | "\t\t\t\t\"pvvv\": 0,\n" +
57 | "\t\t\t\t\"mediaTotal\": 0\n" +
58 | "\t\t\t}]\n" +
59 | "\t\t}, {\n" +
60 | "\t\t\t\"id\": 42,\n" +
61 | "\t\t\t\"type\": 2,\n" +
62 | "\t\t\t\"title\": \"夏日游记\",\n" +
63 | "\t\t\t\"image\": \"http://ztjy-img-dev.szytest.com/ztnew/ad/img/2018/09/19/1537345740502918.gif\",\n" +
64 | "\t\t\t\"imgWidth\": 300,\n" +
65 | "\t\t\t\"imgHeight\": 300,\n" +
66 | "\t\t\t\"number\": 1,\n" +
67 | "\t\t\t\"titleType\": 0,\n" +
68 | "\t\t\t\"isMainPush\": 0,\n" +
69 | "\t\t\t\"isMore\": 1,\n" +
70 | "\t\t\t\"contentList\": []\n" +
71 | "\t\t}, {\n" +
72 | "\t\t\t\"id\": 35,\n" +
73 | "\t\t\t\"type\": 2,\n" +
74 | "\t\t\t\"title\": \"除了长得好看一无是处\",\n" +
75 | "\t\t\t\"image\": \"http://ztjy-img-dev.szytest.com/ztnew/ad/img/2018/09/18/1537243176763496.jpg\",\n" +
76 | "\t\t\t\"imgWidth\": 200,\n" +
77 | "\t\t\t\"imgHeight\": 200,\n" +
78 | "\t\t\t\"number\": 1,\n" +
79 | "\t\t\t\"titleType\": 0,\n" +
80 | "\t\t\t\"isMainPush\": 0,\n" +
81 | "\t\t\t\"isMore\": 0,\n" +
82 | "\t\t\t\"contentList\": []\n" +
83 | "\t\t}, {\n" +
84 | "\t\t\t\"id\": 55,\n" +
85 | "\t\t\t\"type\": 2,\n" +
86 | "\t\t\t\"title\": \"竖屏视频测试1\",\n" +
87 | "\t\t\t\"image\": \"http://ztjy-img-dev.szytest.com/ztnew/ad/img/2019/01/03/1546500035149021.png\",\n" +
88 | "\t\t\t\"imgWidth\": 698,\n" +
89 | "\t\t\t\"imgHeight\": 267,\n" +
90 | "\t\t\t\"number\": 1,\n" +
91 | "\t\t\t\"titleType\": 0,\n" +
92 | "\t\t\t\"isMainPush\": 0,\n" +
93 | "\t\t\t\"isMore\": 0,\n" +
94 | "\t\t\t\"contentList\": [{\n" +
95 | "\t\t\t\t\"contentType\": 26,\n" +
96 | "\t\t\t\t\"contentId\": \"1018\",\n" +
97 | "\t\t\t\t\"image\": \"http://ztjy-img-dev.szytest.com/ztnew/ad/img/2019/01/03/1546501303819644.png\",\n" +
98 | "\t\t\t\t\"title\": \"竖屏视频专题1\",\n" +
99 | "\t\t\t\t\"desc\": \"\",\n" +
100 | "\t\t\t\t\"isMainPush\": 0,\n" +
101 | "\t\t\t\t\"beginTime\": 1546501295000,\n" +
102 | "\t\t\t\t\"pvvv\": 0,\n" +
103 | "\t\t\t\t\"mediaTotal\": 0\n" +
104 | "\t\t\t}]\n" +
105 | "\t\t}]\n" +
106 | "\t}\n" +
107 | "}";
108 | }
109 |
--------------------------------------------------------------------------------
/src/main/java/bean/DataBean.java:
--------------------------------------------------------------------------------
1 | package bean;
2 |
3 | import java.util.List;
4 |
5 | public class DataBean {
6 | /**
7 | * image : http://ztjy-img-dev.szytest.com/ztnew/ad/img/2018/09/28/1538124681903616.png
8 | * number : 1
9 | * titleType : 0
10 | * imgWidth : 74
11 | * isMainPush : 0
12 | * isMore : 1
13 | * imgHeight : 71
14 | * id : 47
15 | * type : 2
16 | * title : 回归版块测试
17 | * contentList : [{"image":"http://ztjy-img-dev.szytest.com/ztnew/ad/img/2019/01/16/1547630094383987.png","pvvv":0,"mediaTotal":0,"contentId":"1017","isMainPush":0,"beginTime":1547630051000,"title":"小五新增专题001","contentType":26,"desc":""}]
18 | */
19 |
20 | private String image;
21 | private int number;
22 | private int titleType;
23 | private int imgWidth;
24 | private int isMainPush;
25 | private int isMore;
26 | private int imgHeight;
27 | private int id;
28 | private int type;
29 | private String title;
30 | private List contentList;
31 |
32 | public String getImage() {
33 | return image;
34 | }
35 |
36 | public void setImage(String image) {
37 | this.image = image;
38 | }
39 |
40 | public int getNumber() {
41 | return number;
42 | }
43 |
44 | public void setNumber(int number) {
45 | this.number = number;
46 | }
47 |
48 | public int getTitleType() {
49 | return titleType;
50 | }
51 |
52 | public void setTitleType(int titleType) {
53 | this.titleType = titleType;
54 | }
55 |
56 | public int getImgWidth() {
57 | return imgWidth;
58 | }
59 |
60 | public void setImgWidth(int imgWidth) {
61 | this.imgWidth = imgWidth;
62 | }
63 |
64 | public int getIsMainPush() {
65 | return isMainPush;
66 | }
67 |
68 | public void setIsMainPush(int isMainPush) {
69 | this.isMainPush = isMainPush;
70 | }
71 |
72 | public int getIsMore() {
73 | return isMore;
74 | }
75 |
76 | public void setIsMore(int isMore) {
77 | this.isMore = isMore;
78 | }
79 |
80 | public int getImgHeight() {
81 | return imgHeight;
82 | }
83 |
84 | public void setImgHeight(int imgHeight) {
85 | this.imgHeight = imgHeight;
86 | }
87 |
88 | public int getId() {
89 | return id;
90 | }
91 |
92 | public void setId(int id) {
93 | this.id = id;
94 | }
95 |
96 | public int getType() {
97 | return type;
98 | }
99 |
100 | public void setType(int type) {
101 | this.type = type;
102 | }
103 |
104 | public String getTitle() {
105 | return title;
106 | }
107 |
108 | public void setTitle(String title) {
109 | this.title = title;
110 | }
111 |
112 | public List getContentList() {
113 | return contentList;
114 | }
115 |
116 | public void setContentList(List contentList) {
117 | this.contentList = contentList;
118 | }
119 |
120 | public static class ContentListBean {
121 | /**
122 | * image : http://ztjy-img-dev.szytest.com/ztnew/ad/img/2019/01/16/1547630094383987.png
123 | * pvvv : 0
124 | * mediaTotal : 0
125 | * contentId : 1017
126 | * isMainPush : 0
127 | * beginTime : 1547630051000
128 | * title : 小五新增专题001
129 | * contentType : 26
130 | * desc :
131 | */
132 |
133 | private String image;
134 | private int pvvv;
135 | private int mediaTotal;
136 | private String contentId;
137 | private int isMainPush;
138 | private long beginTime;
139 | private String title;
140 | private int contentType;
141 | private String desc;
142 |
143 | public String getImage() {
144 | return image;
145 | }
146 |
147 | public void setImage(String image) {
148 | this.image = image;
149 | }
150 |
151 | public int getPvvv() {
152 | return pvvv;
153 | }
154 |
155 | public void setPvvv(int pvvv) {
156 | this.pvvv = pvvv;
157 | }
158 |
159 | public int getMediaTotal() {
160 | return mediaTotal;
161 | }
162 |
163 | public void setMediaTotal(int mediaTotal) {
164 | this.mediaTotal = mediaTotal;
165 | }
166 |
167 | public String getContentId() {
168 | return contentId;
169 | }
170 |
171 | public void setContentId(String contentId) {
172 | this.contentId = contentId;
173 | }
174 |
175 | public int getIsMainPush() {
176 | return isMainPush;
177 | }
178 |
179 | public void setIsMainPush(int isMainPush) {
180 | this.isMainPush = isMainPush;
181 | }
182 |
183 | public long getBeginTime() {
184 | return beginTime;
185 | }
186 |
187 | public void setBeginTime(long beginTime) {
188 | this.beginTime = beginTime;
189 | }
190 |
191 | public String getTitle() {
192 | return title;
193 | }
194 |
195 | public void setTitle(String title) {
196 | this.title = title;
197 | }
198 |
199 | public int getContentType() {
200 | return contentType;
201 | }
202 |
203 | public void setContentType(int contentType) {
204 | this.contentType = contentType;
205 | }
206 |
207 | public String getDesc() {
208 | return desc;
209 | }
210 |
211 | public void setDesc(String desc) {
212 | this.desc = desc;
213 | }
214 | }
215 | }
216 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/src/main/java/bean/Bean.java:
--------------------------------------------------------------------------------
1 | package bean;
2 |
3 | import java.util.List;
4 |
5 | public class Bean {
6 | /**
7 | * code : 10000
8 | * message : 成功
9 | * body : {"data":[{"id":47,"type":2,"title":"回归版块测试","image":"http://ztjy-img-dev.szytest.com/ztnew/ad/img/2018/09/28/1538124681903616.png","imgWidth":74,"imgHeight":71,"number":1,"titleType":0,"isMainPush":0,"isMore":1,"contentList":[{"contentType":26,"contentId":"1017","image":"http://ztjy-img-dev.szytest.com/ztnew/ad/img/2019/01/16/1547630094383987.png","title":"小五新增专题001","desc":"","isMainPush":0,"beginTime":1547630051000,"pvvv":0,"mediaTotal":0}]},{"id":42,"type":2,"title":"夏日游记","image":"http://ztjy-img-dev.szytest.com/ztnew/ad/img/2018/09/19/1537345740502918.gif","imgWidth":300,"imgHeight":300,"number":1,"titleType":0,"isMainPush":0,"isMore":1,"contentList":[]},{"id":35,"type":2,"title":"除了长得好看一无是处","image":"http://ztjy-img-dev.szytest.com/ztnew/ad/img/2018/09/18/1537243176763496.jpg","imgWidth":200,"imgHeight":200,"number":1,"titleType":0,"isMainPush":0,"isMore":0,"contentList":[]},{"id":55,"type":2,"title":"竖屏视频测试1","image":"http://ztjy-img-dev.szytest.com/ztnew/ad/img/2019/01/03/1546500035149021.png","imgWidth":698,"imgHeight":267,"number":1,"titleType":0,"isMainPush":0,"isMore":0,"contentList":[{"contentType":26,"contentId":"1018","image":"http://ztjy-img-dev.szytest.com/ztnew/ad/img/2019/01/03/1546501303819644.png","title":"竖屏视频专题1","desc":"","isMainPush":0,"beginTime":1546501295000,"pvvv":0,"mediaTotal":0}]}]}
10 | */
11 |
12 | private int code;
13 | private String message;
14 | private BodyBean body;
15 |
16 | public int getCode() {
17 | return code;
18 | }
19 |
20 | public void setCode(int code) {
21 | this.code = code;
22 | }
23 |
24 | public String getMessage() {
25 | return message;
26 | }
27 |
28 | public void setMessage(String message) {
29 | this.message = message;
30 | }
31 |
32 | public BodyBean getBody() {
33 | return body;
34 | }
35 |
36 | public void setBody(BodyBean body) {
37 | this.body = body;
38 | }
39 |
40 | public static class BodyBean {
41 | private List data;
42 |
43 | public List getData() {
44 | return data;
45 | }
46 |
47 | public void setData(List data) {
48 | this.data = data;
49 | }
50 |
51 | public static class DataBean {
52 | /**
53 | * id : 47
54 | * type : 2
55 | * title : 回归版块测试
56 | * image : http://ztjy-img-dev.szytest.com/ztnew/ad/img/2018/09/28/1538124681903616.png
57 | * imgWidth : 74
58 | * imgHeight : 71
59 | * number : 1
60 | * titleType : 0
61 | * isMainPush : 0
62 | * isMore : 1
63 | * contentList : [{"contentType":26,"contentId":"1017","image":"http://ztjy-img-dev.szytest.com/ztnew/ad/img/2019/01/16/1547630094383987.png","title":"小五新增专题001","desc":"","isMainPush":0,"beginTime":1547630051000,"pvvv":0,"mediaTotal":0}]
64 | */
65 |
66 | private int id;
67 | private int type;
68 | private String title;
69 | private String image;
70 | private int imgWidth;
71 | private int imgHeight;
72 | private int number;
73 | private int titleType;
74 | private int isMainPush;
75 | private int isMore;
76 | private List contentList;
77 |
78 | public int getId() {
79 | return id;
80 | }
81 |
82 | public void setId(int id) {
83 | this.id = id;
84 | }
85 |
86 | public int getType() {
87 | return type;
88 | }
89 |
90 | public void setType(int type) {
91 | this.type = type;
92 | }
93 |
94 | public String getTitle() {
95 | return title;
96 | }
97 |
98 | public void setTitle(String title) {
99 | this.title = title;
100 | }
101 |
102 | public String getImage() {
103 | return image;
104 | }
105 |
106 | public void setImage(String image) {
107 | this.image = image;
108 | }
109 |
110 | public int getImgWidth() {
111 | return imgWidth;
112 | }
113 |
114 | public void setImgWidth(int imgWidth) {
115 | this.imgWidth = imgWidth;
116 | }
117 |
118 | public int getImgHeight() {
119 | return imgHeight;
120 | }
121 |
122 | public void setImgHeight(int imgHeight) {
123 | this.imgHeight = imgHeight;
124 | }
125 |
126 | public int getNumber() {
127 | return number;
128 | }
129 |
130 | public void setNumber(int number) {
131 | this.number = number;
132 | }
133 |
134 | public int getTitleType() {
135 | return titleType;
136 | }
137 |
138 | public void setTitleType(int titleType) {
139 | this.titleType = titleType;
140 | }
141 |
142 | public int getIsMainPush() {
143 | return isMainPush;
144 | }
145 |
146 | public void setIsMainPush(int isMainPush) {
147 | this.isMainPush = isMainPush;
148 | }
149 |
150 | public int getIsMore() {
151 | return isMore;
152 | }
153 |
154 | public void setIsMore(int isMore) {
155 | this.isMore = isMore;
156 | }
157 |
158 | public List getContentList() {
159 | return contentList;
160 | }
161 |
162 | public void setContentList(List contentList) {
163 | this.contentList = contentList;
164 | }
165 |
166 | public static class ContentListBean {
167 | /**
168 | * contentType : 26
169 | * contentId : 1017
170 | * image : http://ztjy-img-dev.szytest.com/ztnew/ad/img/2019/01/16/1547630094383987.png
171 | * title : 小五新增专题001
172 | * desc :
173 | * isMainPush : 0
174 | * beginTime : 1547630051000
175 | * pvvv : 0
176 | * mediaTotal : 0
177 | */
178 |
179 | private int contentType;
180 | private String contentId;
181 | private String image;
182 | private String title;
183 | private String desc;
184 | private int isMainPush;
185 | private long beginTime;
186 | private int pvvv;
187 | private int mediaTotal;
188 |
189 | public int getContentType() {
190 | return contentType;
191 | }
192 |
193 | public void setContentType(int contentType) {
194 | this.contentType = contentType;
195 | }
196 |
197 | public String getContentId() {
198 | return contentId;
199 | }
200 |
201 | public void setContentId(String contentId) {
202 | this.contentId = contentId;
203 | }
204 |
205 | public String getImage() {
206 | return image;
207 | }
208 |
209 | public void setImage(String image) {
210 | this.image = image;
211 | }
212 |
213 | public String getTitle() {
214 | return title;
215 | }
216 |
217 | public void setTitle(String title) {
218 | this.title = title;
219 | }
220 |
221 | public String getDesc() {
222 | return desc;
223 | }
224 |
225 | public void setDesc(String desc) {
226 | this.desc = desc;
227 | }
228 |
229 | public int getIsMainPush() {
230 | return isMainPush;
231 | }
232 |
233 | public void setIsMainPush(int isMainPush) {
234 | this.isMainPush = isMainPush;
235 | }
236 |
237 | public long getBeginTime() {
238 | return beginTime;
239 | }
240 |
241 | public void setBeginTime(long beginTime) {
242 | this.beginTime = beginTime;
243 | }
244 |
245 | public int getPvvv() {
246 | return pvvv;
247 | }
248 |
249 | public void setPvvv(int pvvv) {
250 | this.pvvv = pvvv;
251 | }
252 |
253 | public int getMediaTotal() {
254 | return mediaTotal;
255 | }
256 |
257 | public void setMediaTotal(int mediaTotal) {
258 | this.mediaTotal = mediaTotal;
259 | }
260 | }
261 | }
262 | }
263 | }
264 |
--------------------------------------------------------------------------------