Commit 3e214bbc33b7c3e8ce6258c111cb12d88e2006a2
1 parent
c806dcc4
Exists in
master
1.工具JAR更新
Showing
2 changed files
with
72 additions
and
2 deletions
Show diff stats
build.gradle
@@ -26,7 +26,8 @@ dependencies { | @@ -26,7 +26,8 @@ dependencies { | ||
26 | "org.apache.velocity:velocity:1.6.4", | 26 | "org.apache.velocity:velocity:1.6.4", |
27 | "com.squareup.okhttp3:okhttp:3.14.1", | 27 | "com.squareup.okhttp3:okhttp:3.14.1", |
28 | "com.belerweb:pinyin4j:2.5.1", | 28 | "com.belerweb:pinyin4j:2.5.1", |
29 | - "org.slf4j:slf4j-api:1.7.28" | 29 | + "org.slf4j:slf4j-api:1.7.28", |
30 | + "net.sf.json-lib:json-lib:2.2.3:jdk15" | ||
30 | ) | 31 | ) |
31 | } | 32 | } |
32 | 33 | ||
@@ -39,6 +40,10 @@ task sourcesJar(type: Jar, dependsOn: classes) { | @@ -39,6 +40,10 @@ task sourcesJar(type: Jar, dependsOn: classes) { | ||
39 | from sourceSets.main.allSource | 40 | from sourceSets.main.allSource |
40 | } | 41 | } |
41 | 42 | ||
43 | +tasks.withType(JavaCompile) { | ||
44 | + options.encoding = "UTF-8" | ||
45 | +} | ||
46 | + | ||
42 | artifacts { | 47 | artifacts { |
43 | archives sourcesJar | 48 | archives sourcesJar |
44 | } | 49 | } |
@@ -54,7 +59,7 @@ uploadArchives { | @@ -54,7 +59,7 @@ uploadArchives { | ||
54 | authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD) | 59 | authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD) |
55 | } | 60 | } |
56 | pom.project { | 61 | pom.project { |
57 | - version '1.1.23' | 62 | + version '1.1.24' |
58 | artifactId ARTIFACT_Id | 63 | artifactId ARTIFACT_Id |
59 | groupId GROUP_ID | 64 | groupId GROUP_ID |
60 | packaging TYPE | 65 | packaging TYPE |
@@ -0,0 +1,65 @@ | @@ -0,0 +1,65 @@ | ||
1 | +package com.taover.util; | ||
2 | + | ||
3 | +import java.util.Iterator; | ||
4 | + | ||
5 | +import net.sf.json.JSONArray; | ||
6 | +import net.sf.json.JSONObject; | ||
7 | + | ||
8 | +public class UtilJSON { | ||
9 | + public static void removeJsonNull(JSONObject data){ | ||
10 | + if(data == null || data.isNullObject()){ | ||
11 | + return; | ||
12 | + } | ||
13 | + Iterator<String> keyIter = data.keys(); | ||
14 | + while(keyIter.hasNext()){ | ||
15 | + String keyItem = keyIter.next(); | ||
16 | + Object value = data.get(keyItem); | ||
17 | + | ||
18 | + if(isJsonNull(value)) { | ||
19 | + data.put(keyItem, ""); | ||
20 | + } | ||
21 | + | ||
22 | + if(value instanceof JSONObject){ | ||
23 | + removeJsonNull((JSONObject)value); | ||
24 | + continue; | ||
25 | + } | ||
26 | + | ||
27 | + if(value instanceof JSONArray){ | ||
28 | + removeJsonNull((JSONArray)value); | ||
29 | + } | ||
30 | + } | ||
31 | + } | ||
32 | + | ||
33 | + public static boolean isJsonNull(Object data){ | ||
34 | + if(data == null){ | ||
35 | + return true; | ||
36 | + } | ||
37 | + if(!(data instanceof String) && data.toString().equals("null")){ | ||
38 | + return true; | ||
39 | + } | ||
40 | + if(data instanceof JSONObject && ((JSONObject) data).isNullObject()){ | ||
41 | + return true; | ||
42 | + } | ||
43 | + return false; | ||
44 | + } | ||
45 | + | ||
46 | + public static void removeJsonNull(JSONArray dataArr){ | ||
47 | + if(dataArr == null){ | ||
48 | + return; | ||
49 | + } | ||
50 | + for(int i=0; i<dataArr.size(); ++i){ | ||
51 | + JSONObject dataItem = dataArr.optJSONObject(i); | ||
52 | + if(dataItem.isNullObject()){ | ||
53 | + dataArr.remove(i); | ||
54 | + continue; | ||
55 | + } | ||
56 | + removeJsonNull(dataItem); | ||
57 | + } | ||
58 | + } | ||
59 | + | ||
60 | + public static void main(String[] args){ | ||
61 | + JSONObject data = JSONObject.fromObject("{\"message\":\"文字解析成功\",\"status\":true,\"statusCode\":\"null\",\"result\":{\"items\":[{\"district\":\"隆化县\",\"city\":\"承德市\",\"province\":\"河北省\",\"phone\":\"13621051230\",\"name\":{\"first_name\":\"wang\",\"second_name\":\"bin\",\"full_name\":null},\"address\":\"东阿超村\"}]}}"); | ||
62 | + removeJsonNull(data); | ||
63 | + System.out.println(data.toString()); | ||
64 | + } | ||
65 | +} |