From 3e214bbc33b7c3e8ce6258c111cb12d88e2006a2 Mon Sep 17 00:00:00 2001 From: 王彬 Date: Fri, 15 Nov 2019 11:07:11 +0800 Subject: [PATCH] 1.工具JAR更新 --- build.gradle | 9 +++++++-- src/main/java/com/taover/util/UtilJSON.java | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/taover/util/UtilJSON.java diff --git a/build.gradle b/build.gradle index 10070f4..bc3ebaa 100644 --- a/build.gradle +++ b/build.gradle @@ -26,7 +26,8 @@ dependencies { "org.apache.velocity:velocity:1.6.4", "com.squareup.okhttp3:okhttp:3.14.1", "com.belerweb:pinyin4j:2.5.1", - "org.slf4j:slf4j-api:1.7.28" + "org.slf4j:slf4j-api:1.7.28", + "net.sf.json-lib:json-lib:2.2.3:jdk15" ) } @@ -39,6 +40,10 @@ task sourcesJar(type: Jar, dependsOn: classes) { from sourceSets.main.allSource } +tasks.withType(JavaCompile) { + options.encoding = "UTF-8" +} + artifacts { archives sourcesJar } @@ -54,7 +59,7 @@ uploadArchives { authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD) } pom.project { - version '1.1.23' + version '1.1.24' artifactId ARTIFACT_Id groupId GROUP_ID packaging TYPE diff --git a/src/main/java/com/taover/util/UtilJSON.java b/src/main/java/com/taover/util/UtilJSON.java new file mode 100644 index 0000000..65696ca --- /dev/null +++ b/src/main/java/com/taover/util/UtilJSON.java @@ -0,0 +1,65 @@ +package com.taover.util; + +import java.util.Iterator; + +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + +public class UtilJSON { + public static void removeJsonNull(JSONObject data){ + if(data == null || data.isNullObject()){ + return; + } + Iterator keyIter = data.keys(); + while(keyIter.hasNext()){ + String keyItem = keyIter.next(); + Object value = data.get(keyItem); + + if(isJsonNull(value)) { + data.put(keyItem, ""); + } + + if(value instanceof JSONObject){ + removeJsonNull((JSONObject)value); + continue; + } + + if(value instanceof JSONArray){ + removeJsonNull((JSONArray)value); + } + } + } + + public static boolean isJsonNull(Object data){ + if(data == null){ + return true; + } + if(!(data instanceof String) && data.toString().equals("null")){ + return true; + } + if(data instanceof JSONObject && ((JSONObject) data).isNullObject()){ + return true; + } + return false; + } + + public static void removeJsonNull(JSONArray dataArr){ + if(dataArr == null){ + return; + } + for(int i=0; i