【笔记分享】获取Json数据的所有Key
private static readonly List<string> ListStrings = new List<string>(); /// <summary> /// 获取所有不同的key /// </summary> /// <param name="jObject"></param> private static void GetAllKeys(JObject jObject) { foreach (var keyValuePair in jObject) { // var keyStr = keyValuePair.Key.ToUpper(); var keyStr = keyValuePair.Key; // 去重 if (!ListStrings.Contains(keyStr)) { ListStrings.Add(keyStr); } switch (keyValuePair.Value) { case JObject jc: GetAllKeys(jc); break; case JArray ja: { foreach (var jToken in ja) { jObject = jToken as JObject; GetAllKeys(jObject); } break; } } } }
/// <summary> /// 获取两个list中不同的key /// </summary> /// <param name="formalObj"></param> /// <param name="newObj"></param> /// <returns></returns> private static List<string> GetDiff(JObject formalObj, JObject newObj) { // 标准的list GetAllKeys(formalObj); var list1 = ListStrings.ToList(); // 清空 ListStrings.Clear(); // 新的list GetAllKeys(newObj); var list2 = ListStrings.ToList(); ListStrings.Clear(); var diffList = list2.Where(s1 => !list1.Contains(s1)).ToList(); return diffList; }
【笔记分享】获取Json数据的所有Key
private static readonly List<string> ListStrings = new List<string>();/// <summary>/// 获取所有不同的key/// </summary>/// <param n...
点击下载文档
本文2024-09-16 17:24:04发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-15470.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章