类型传入255,也作为删除该字段

master
Matthew 10 months ago
parent bc7251926f
commit 4f6a20c101

@ -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);

Loading…
Cancel
Save