/// <summary> /// 将类序列化成 字符串 /// </summary> /// <param name="obj"></param> /// <returns></returns> public static string SerializeObject(object obj) { try { JavaScriptSerializer jss = new JavaScriptSerializer(); return(jss.Serialize(obj)); } catch (Exception ex) { ClassLoger.Error("JsonHelper/DeserializeObject", ex.Message); } return(null); }
/// <summary> /// 解析json 返回对应的对象 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="jsonstr"></param> /// <returns></returns> public static T DeserializeObject <T>(string jsonstr) { try { if (!string.IsNullOrEmpty(jsonstr)) { JavaScriptSerializer jss = new JavaScriptSerializer(); return(jss.Deserialize <T>(jsonstr)); } } catch (Exception ex) { ClassLoger.Error("JsonHelper/DeserializeObject", ex.Message); } return(default(T)); }
/// <summary> /// 解析json 返回object 数组 /// </summary> /// <param name="jsonstr"></param> /// <returns></returns> public static object[] Deserialize(string jsonstr) { try { if (!string.IsNullOrEmpty(jsonstr)) { JavaScriptSerializer jss = new JavaScriptSerializer(); object d = jss.DeserializeObject(jsonstr); return((object[])d); } } catch (Exception ex) { ClassLoger.Error("JsonHelper/Deserialize", ex.Message); } return(null); }
/// <summary> /// 解析json 返回dict对象 /// </summary> /// <param name="jsonstr"></param> /// <returns></returns> public static Dictionary <string, object> DeserializeObject(string jsonstr) { List <object> list = new List <object>(); try { if (!string.IsNullOrEmpty(jsonstr)) { JavaScriptSerializer jss = new JavaScriptSerializer(); object d = jss.DeserializeObject(jsonstr); return((Dictionary <string, object>)d); } } catch (Exception ex) { ClassLoger.Error("JsonHelper/DeserializeObject", ex.Message); } return(null); }
public void Start() { ClassLoger.DEBUG("clearlogs/Start", "日志清理开始"); th = new Thread(new ThreadStart(Worker)); th.Start(); }