Using system; using system. collections. generic; using system. web; using system. runtime. serialization. JSON; using system. LINQ; using system. text; using system. io; using system. text. regularexpressions; namespace jsonhelper {public class jsonclass {// <summary> // JSON serialization /// </Summary> /// <typeparam name = "T"> Object Type </ typeparam> // <Param name = "T"> serialized object </param> /// <returns> </returns> Public static string jsonserializer <t> (T) {datacontractjsonserializer SER = new datacontractjsonserializer (typeof (t); memorystream MS = new memorystream (); Ser. writeobject (MS, T); string jsonstring = encoding. utf8.getstring (Ms. toarray (); Ms. close (); string P = @ "\/date \ (\ D +) \ + \ D + \)\\/"; matchevaluator = new matchevaluator (convertjsondatetodatestring); RegEx Reg = new RegEx (p); jsonstring = reg. replace (jsonstring, matchevaluator); Return jsonstring ;} /// <summary> /// JSON deserialization /// </Summary> /// <typeparam name = "T"> Object Type </typeparam> /// <param name = "jsonstring"> deserializing a json string </param> // <returns> </returns> Public static t jsondeserialize <t> (string jsonstring) {string P = @ "\ D {4}-\ D {2}-\ D {2} \ s \ D {2 }:\ d {2 }: \ D {2} "; matchevaluator = new matchevaluator (convertdatestringtojsondate); RegEx Reg = new RegEx (p); jsonstring = reg. replace (jsonstring, matchevaluator); datacontractjsonserializer SER = new datacontractjsonserializer (typeof (t); memorystream MS = new memorystream (encoding. utf8.getbytes (jsonstring); t OBJ = (t) Ser. readobject (MS); Return OBJ;} Private Static string convertjsondatetodatestring (Match m) {string result = string. empty; datetime dt = new datetime (1970, 1, 1); dt = DT. addmilliseconds (Long. parse (M. groups [1]. value); dt = DT. tolocaltime (); Result = DT. tostring ("yyyy-mm-dd hh: mm: SS"); return result;} Private Static string convertdatestringtojsondate (Match m) {string result = string. empty; datetime dt = datetime. parse (M. groups [0]. value); dt = DT. touniversaltime (); timespan Ts = DT-datetime. parse ("1970-01-01"); Result = string. format ("\/date ({0} + 0800) \/", ts. totalmilliseconds); return result ;}}}