//object 转json格式字符串
public static string ObjectToJsonString(this object obj) { return JsonConvert.SerializeObject(obj).Replace("\r\n", ""); } //json字符串转实体 public static T JsonToObject<T>(this string json) { return JsonConvert.DeserializeObject<T>(json); }
//对象转JSON
public static string ObjToJson(object obj) { StringBuilder sb = new StringBuilder(); JavaScriptSerializer jserializer = new JavaScriptSerializer(); jserializer.MaxJsonLength = int.MaxValue; jserializer.Serialize(obj, sb); return sb.ToString().Replace("/u0026", "&"); }//json转对象
public static T JsonToObj<T>(string json) { JavaScriptSerializer jserializer = new JavaScriptSerializer(); jserializer.MaxJsonLength = int.MaxValue; if (string.IsNullOrEmpty(json)) json = "{}"; T obj = jserializer.Deserialize<T>(json); return obj; }