【文件属性】:
文件名称:Json序列化与反序列化方法封装类
文件大小:2KB
文件格式:CS
更新时间:2016-09-14 08:14:32
asp.net 序列化json
///
/// Json序列化与反序列化方法封装类
///
public static class JsonConvert
{
///
/// 序列化模型对象为Json
///
/// 模型类型
/// 模型对象
///
public static string GetJson(T model) where T : new()
{
return new JavaScriptSerializer().Serialize(model);
}
///
/// 序列化模型集合为Json
///
/// 集合对象类型
/// 集合对象
///
public static string GetJson(List model) where T : new()
{
return new JavaScriptSerializer().Serialize(model);
}
///
/// 反序列化Json为模型对象
///
/// 模型对象类型
/// Json字符串
///
public static T GetModel(string Json) where T : new()
{
return new JavaScriptSerializer().Deserialize(Json);
}
///
/// 反序列化Json为模型对象集合
///
/// 集合对象类型
/// Json字符串
///
public static List GetList(string Json) where T : new()
{
return new JavaScriptSerializer().Deserialize>(Json);
}
}