Newtonsoft.Json
作者:互联网
1、序列化
string jsonStr = JsonConvert.SerializeObject(obj)
2、反序列化
T obj = JsonConvert.DeserializeObject
3、Newtonsoft.Json 扩展方法类
/// <summary>
/// Newtonsoft.Json的扩展方法类
/// </summary>
public static class NewtonsoftJsonExtension
{
/// <summary>
/// 将Json字符串反序列化为对象实例——Newtonsoft.Json
/// </summary>
/// <typeparam name="T">对象类型</typeparam>
/// <param name="jsonString">Json字符串</param>
/// <returns>对象实例</returns>
public static T DeserializeObjectFromJson_NJ<T>(this string jsonString)
{
return JsonConvert.DeserializeObject<T>(jsonString);
}
/// <summary>
/// 将对象实例序列化为Json字符串——Newtonsoft.Json
/// </summary>
/// <typeparam name="T">对象类型</typeparam>
/// <param name="obj">对象实例</param>
/// <returns>Json字符串</returns>
public static string SerializeObjectToJson_NJ<T>(this T obj)
{
return JsonConvert.SerializeObject(obj);
}
}
标签:Newtonsoft,obj,JsonConvert,Json,实例,序列化 来源: https://www.cnblogs.com/his365/p/16607245.html