using System; using System.Collections; using System.Collections.Generic; using Newtonsoft.Json; using SDKCSharp.Request; namespace SDKCSharp.Utility { /// /// JSON序列化/反序列化工具 /// 使用Newtonsoft.Json组件,详见:https://www.newtonsoft.com/json /// public class JsonUtil { public const string EMPTY_JSON = "{}"; /// /// JSON字符串转化成对象 /// /// /// /// public static T ParseObject(string json) { return JsonConvert.DeserializeObject(json);// //反序列化 } /// /// json字符串转换成Dictionary /// /// The to dictionary. /// Json. public static Dictionary ParseToDictionary(string json) { return JsonConvert.DeserializeObject>(json); } /// /// 对象转换成json字符串 /// /// /// public static string ToJSONString(object obj) { if (obj == null) { return EMPTY_JSON; } return JsonConvert.SerializeObject(obj); } } }