From 4f6a20c1012b386ee4353d4435aa3d8543771f9d Mon Sep 17 00:00:00 2001 From: Matthew Date: Sat, 10 Aug 2024 20:17:49 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E4=BC=A0=E5=85=A5255?= =?UTF-8?q?=EF=BC=8C=E4=B9=9F=E4=BD=9C=E4=B8=BA=E5=88=A0=E9=99=A4=E8=AF=A5?= =?UTF-8?q?=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/src/main/java/com/xypower/common/JSONUtils.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/com/xypower/common/JSONUtils.java b/common/src/main/java/com/xypower/common/JSONUtils.java index ec71b146..f27f1c8d 100644 --- a/common/src/main/java/com/xypower/common/JSONUtils.java +++ b/common/src/main/java/com/xypower/common/JSONUtils.java @@ -218,6 +218,7 @@ public class JSONUtils { int arrayIndex = 0; boolean isArray = false; String fieldName = null; + boolean removeNode = val == null || fieldType == 255; JSONObject node = jsonObject; int i = 0; @@ -235,7 +236,7 @@ public class JSONUtils { fieldName = fields[i].substring(0, pos); arrayIndex = Integer.parseInt(fields[i].substring(pos + 1, pos2 - pos - 1)); - if (!node.has(fieldName) && val == null) { + if (!node.has(fieldName) && removeNode) { return true; } JSONArray jsonArray = node.optJSONArray(fieldName); @@ -250,7 +251,7 @@ public class JSONUtils { node = jsonArray.optJSONObject(arrayIndex); } else { if (!node.has(fields[i])) { - if (val == null) + if (removeNode) return true; else { node.put(fields[i], new JSONObject()); @@ -261,10 +262,10 @@ public class JSONUtils { } if (node == null) { - return (val == null); + return removeNode; } - if (val == null) { + if (removeNode) { node.remove(fields[i]); } else { node.put(fields[i], val);