using System.Collections.Generic; using Newtonsoft.Json.Linq; namespace Alipay.EasySDK.Kernel.Util { /// /// 字典工具类 /// public static class DictionaryUtil { /// /// 将字典各层次Value中的JObject和JArray转换成C#标准库中的Dictionary和List /// /// 输入字典 /// 转换后的输出字典 public static Dictionary ObjToDictionary(Dictionary dicObj) { Dictionary dic = new Dictionary(); foreach (string key in dicObj.Keys) { if (dicObj[key] is JArray) { List> dicObjList = ((JArray)dicObj[key]).ToObject>>(); List> dicList = new List>(); foreach (Dictionary objItem in dicObjList) { dicList.Add(ObjToDictionary(objItem)); } dic.Add(key, dicList); } else if (dicObj[key] is JObject) { Dictionary dicJObj = ((JObject)dicObj[key]).ToObject>(); dic.Add(key, ObjToDictionary(dicJObj)); } else { dic.Add(key, dicObj[key]); } } return dic; } } }