using Newtonsoft.Json;
namespace ProductionLineMonitor.Core.Utils
{
public static class JsonHelper
{
///
/// 将JSON字符串反序列化成对象
///
///
///
///
///
public static T ToObject(T baseEntity, string strJson)
{
return JsonConvert.DeserializeAnonymousType(strJson, baseEntity);
}
///
/// 将Json反序列化成对象
///
///
///
///
public static T ToObject(this string strJson)
{
return JsonConvert.DeserializeObject(strJson);
}
///
/// 将对象转换层JSON字符串
///
///
///
///
public static string ToJson(this T data)
{
return JsonConvert.SerializeObject(data);
}
}
}