using System.Web.Script.Serialization; public class JsonHelper { public static string ObjectToJsonString<T>(T t) { JavaScriptSerializer js = new JavaScriptSerializer(); //序列化方法:将T类型对象转换为Json字符串 return js.Serialize(t); } public static T JsonStringToObject<T>(string str) { JavaScriptSerializer js = new JavaScriptSerializer(); //反序列化方法:将Json字符串转化为T类型对象 return js.Deserialize<T>(str); } }