using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; namespace KdanCommon.Helpers { public static class DynamicJsonHelper { public static dynamic ToDynamicJson(string jsonString) { try { JObject jo = JObject.Parse(jsonString); return jo as dynamic; } catch { return null; } } public static T GetValueSafety(dynamic value, T defaultValue) { try { var val = (T)value; if (val == null) return defaultValue; else return (T)value; } catch { return defaultValue; } } public static List GetArraySafety(dynamic value) { try { if (value is JArray) return ((JArray)value).Cast().ToList(); } catch { } return null; } } }