public static class JSONHelper { ////// 將對(duì)象轉(zhuǎn)化為Json字符串 /// ///對(duì)象類型 /// 對(duì)象本身 ///JSON字符串 public static string Serializer(this T instanse) { try { DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(T)); using (MemoryStream ms = new MemoryStream()) { js.WriteObject(ms, instanse); ms.Flush(); ms.Seek(0, SeekOrigin.Begin); StreamReader sr = new StreamReader(ms); return sr.ReadToEnd(); } } catch { return String.Empty; } } /// /// 將字符串轉(zhuǎn)化為JSON對(duì)象,如果轉(zhuǎn)換失敗,返回default(T) /// ///對(duì)象類型 /// 字符串 ///轉(zhuǎn)換值 public static T Deserializer(this string s) { try { DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(T)); using (MemoryStream ms = new MemoryStream()) { StreamWriter sw = new StreamWriter(ms); sw.Write(s); sw.Flush(); ms.Seek(0, SeekOrigin.Begin); return (T)js.ReadObject(ms); } } catch { return default(T); } } }
三沙ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書未來市場(chǎng)廣闊!成為創(chuàng)新互聯(lián)建站的ssl證書銷售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:028-86922220(備注:SSL證書合作)期待與您的合作!