From e8cd979bd4195d1e9fd43bcafd20a169bf1dd8b5 Mon Sep 17 00:00:00 2001 From: wangbin Date: Mon, 2 Mar 2020 20:26:23 +0800 Subject: [PATCH] 1.完善jsonutil方法 --- build.gradle | 2 +- src/main/java/com/taover/util/UtilJSON.java | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index d6ed64f..d298d91 100644 --- a/build.gradle +++ b/build.gradle @@ -59,7 +59,7 @@ uploadArchives { authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD) } pom.project { - version '1.1.39' + version '1.1.40' 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 index 65696ca..f8018e0 100644 --- a/src/main/java/com/taover/util/UtilJSON.java +++ b/src/main/java/com/taover/util/UtilJSON.java @@ -57,6 +57,44 @@ public class UtilJSON { } } + public static void replaceJsonNull(JSONObject data, Object target){ + 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, target); + } + + if(value instanceof JSONObject){ + replaceJsonNull((JSONObject)value, target); + continue; + } + + if(value instanceof JSONArray){ + replaceJsonNull((JSONArray)value, target); + } + } + } + + public static void replaceJsonNull(JSONArray dataArr, Object target){ + if(dataArr == null){ + return; + } + for(int i=0; i