项目添加引用System.Web.Extensions
/// <summary> /// 泛型序列化 /// </summary> public class JsonHelper { /// <summary> /// JSON序列化 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="t"></param> /// <returns></returns> static public string ScriptSerialize<T>(T t) { JavaScriptSerializer js = new JavaScriptSerializer(); return js.Serialize(t); } /// <summary> /// JSON反序列化 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="jsonSring"></param> /// <returns></returns> static public T ScriptDeserialize<T>(string jsonSring) { JavaScriptSerializer js = new JavaScriptSerializer(); return js.Deserialize<T>(jsonSring); } }