using Newtonsoft.Json.Linq; using System.Collections.Generic; using System.Linq; namespace Hydro.CommonBase { /// /// JObject扩展 /// //public static class JObjectExtensions //{ // /// // /// 将JObject转化成字典 // /// // /// // /// // public static dict Todict(this JToken json) // { // var propertyValuePairs = json.ToObject(); // ProcessJObjectProperties(propertyValuePairs); // ProcessJArrayProperties(propertyValuePairs); // return propertyValuePairs; // } // private static void ProcessJObjectProperties(dict propertyValuePairs) // { // var objectPropertyNames = (from property in propertyValuePairs // let propertyName = property.Key // let value = property.Value // where value is JObject // select propertyName).ToList(); // objectPropertyNames.ForEach(propertyName => propertyValuePairs[propertyName] = Todict((JObject)propertyValuePairs[propertyName])); // } // private static void ProcessJArrayProperties(dict propertyValuePairs) // { // var arrayPropertyNames = (from property in propertyValuePairs // let propertyName = property.Key // let value = property.Value // where value is JArray // select propertyName).ToList(); // //arrayPropertyNames.ForEach(propertyName => propertyValuePairs[propertyName] = ToArray((JArray)propertyValuePairs[propertyName])); // arrayPropertyNames.ForEach(propertyName => propertyValuePairs[propertyName] = ToList((JArray)propertyValuePairs[propertyName])); // } // /// // /// // /// // /// // /// // public static object[] ToArray(this JArray array) // { // return array.ToObject().Select(ProcessArrayEntry).ToArray(); // } // public static List ToList(this JArray array) // { // return array.ToObject().Select(ProcessArrayEntry).ToList(); // } // private static dynamic ProcessArrayEntry(dynamic value) // { // if (value is JObject) // { // return Todict((JObject)value); // } // if (value is JArray) // { // return ToList((JArray)value); // //return ToArray((JArray)value); // } // return value; // } //} }