using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
namespace EC.Helper.Common
{
public class JsonHelper
{
///
/// Object To Json
///
///
///
public static string ToJson(object obj)
{
return JsonConvert.SerializeObject(obj);
}
///
/// Json To Object
///
///
///
public static object ToObject(string json)
{
return !string.IsNullOrEmpty(json) ? JsonConvert.DeserializeObject(json) : default;
}
///
/// Json To T Object
///
///
///
///
public static T ToObject(string json) where T : class
{
return !string.IsNullOrEmpty(json) ? JsonConvert.DeserializeObject(json) : default;
}
///
/// Json To JObject
///
///
///
public static JObject ToJObject(string json)
{
return ToObject(json);
}
///
/// Json To Object List
///
///
///
///
public static List ToList(string json) where T : class
{
return ToObject>(json);
}
///
/// 深克隆
///
///
///
///
public static T DeepClone(T obj) where T : class
{
string json = ToJson(obj);
return ToObject(json);
}
}
}