private static void RemoveEmpty(JObject jsonObject) { var it = jsonObject.GetEnumerator(); while (it.MoveNext()) { var entry = it.Current; var value = entry.Value; if (value is JArray) { var jsonArray = (JArray)value; if (jsonArray.Count == 0) { it.Remove(); } else { foreach (var o in jsonArray) { var asJsonObject = (JObject)o; RemoveEmpty(asJsonObject); } } } if (value is JObject) { var asJsonObject = (JObject)value; RemoveEmpty(asJsonObject); } if (value == null) { it.Remove(); } if (value is string && string.IsNullOrEmpty(value.ToString())) { it.Remove(); } }

private static void removeEmptyJSONObject jsonObject IteratorMapEntryString Object it = jsonObjectentrySetiterator; while ithasNext MapEntryString Object entry = itnext;

原文地址: https://www.cveoy.top/t/topic/fFU1 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录