A json help class is formed as required by the project.
This is written in the. net3.5 Environment
Public class JsonHelper {// <summary> // convert Json to List <T> /// </summary> /// <typeparam name = "T"> </ typeparam> // <param name = "html"> </param> // <returns> </returns> public static IList <T> JsonToList <T> (string html) {IList <T> result = new List <T> (); html = FormatJson (html); try {DataContractJsonSerializer _ Json = new DataContractJsonSerializer (result. getType (); byte [] _ Using = System. text. encoding. UTF8.GetBytes (html); System. IO. memoryStream _ MemoryStream = new System. IO. memoryStream (_ Using); _ MemoryStream. position = 0; object obj = _ Json. readObject (_ MemoryStream); result = (IList <T>) obj;} catch (Exception) {html = AttributeToVariable (html); DataContractJsonSerializer _ Json = new DataContractJsonSerializer (result. getType (); byte [] _ Using = System. text. encoding. UTF8.GetBytes (html); System. IO. memoryStream _ MemoryStream = new System. IO. memoryStream (_ Using); _ MemoryStream. position = 0; object obj = _ Json. readObject (_ MemoryStream); result = (IList <T>) obj;} return result ;} # region // format the Json string /// <summary> // format the Json string, convert it to List /// </summary> /// <param name = "html"> </param> /// <returns> </returns> public static string formatJson (string value) {string p = @ "(new Date) \ (+ ([0-9,-] +) + (\)"; MatchEvaluator matchEvaluator = new MatchEvaluator (FormatJsonMatch ); regex reg = new Regex (p); bool isfind = reg. isMatch (value); value = reg. replace (value, matchEvaluator); return value ;}/// <summary> // convert the Json serialization time from new Date (1373387734703) to the string "\/Date (1373387734703) \/"// </summary> private static string FormatJsonMatch (Match m) {return string. format ("\" \/Date ({0}) \/\ "", m. groups [2]. value) ;}# endregion // format the Json string # region // format the Date /// <summary> // serialize the time of Json from new Date (1373390933250) or Date (1373390933250) or "\/Date (1373390933250 + 0800) \/"// converted to 17:28:53 // It is mainly used for sending to the front-end // </summary> /// <param name =" html "> </param> // /<returns> </returns> public static string FormatJsonDate (string value) {string p = @ "(new Date) \ (+ ([0-9,-] +) + (\)"; MatchEvaluator matchEvaluator = new MatchEvaluator (FormatJsonDateMatch ); regex reg = new Regex (p); value = reg. replace (value, matchEvaluator); p = @ "(Date) \ (+ ([0-9,-] +) + (\))"; matchEvaluator = new MatchEvaluator (FormatJsonDateMatch); reg = new Regex (p); value = reg. replace (value, matchEvaluator); p = "\" \\\\\\/ "+ @" Date (\ () ([0-9,-] +) ([+]) ([0-9,-] +) (\) "+ "\\\\\\/\""; matchEvaluator = new MatchEvaluator (FormatJsonDateMatch); reg = new Regex (p); value = reg. replace (value, matchEvaluator); return value ;}/// <summary> // serialize the Json time from Date (1294499956278 + 0800) convert to string /// </summary> private static string FormatJsonDateMatch (Match m) {string result = string. empty; DateTime dt = new DateTime (1970, 1, 1); dt = dt. addMilliseconds (long. parse (m. groups [2]. value); dt = dt. toLocalTime (); result = dt. toString ("yyyy-MM-dd HH: mm: ss"); return result ;} # endregion // format the date # region // conversion of attributes and variables /// <summary> // conversion of attributes // set "<address> k _ BackingField ": "1", // convert to "address": "1 ", /// </summary> /// <param name = "value"> </param> /// <returns> </returns> public static string AttributeToVariable (string value) {string p = @ "\ <([A-Z, a-z, 0-9, _] *) \> k _ BackingField "; matchEvaluator matchEvaluator = new MatchEvaluator (AttributeToVariableMatch); Regex reg = new Regex (p); bool isfind = reg. isMatch (value); value = reg. replace (value, matchEvaluator); return value;} private static string AttributeToVariableMatch (Match m) {return m. groups [1]. value;} // <summary> // convert the variable to a property. // convert "address": "1 ", /// convert to "<address> k _ BackingField": "1 ", /// </summary> /// <param name = "value"> </param> /// <returns> </returns> public static string VariableToAttribute (string value) {string p = "\" ([A-Z, a-z, 0-9, _] *) \ "\:"; matchEvaluator matchEvaluator = new MatchEvaluator (VariableToAttributeMatch); Regex reg = new Regex (p); bool isfind = reg. isMatch (value); value = reg. replace (value, matchEvaluator); return value;} private static string VariableToAttributeMatch (Match m) {return string. format ("\" <{0}> k _ BackingField \ ":", m. groups [1]. value) ;}# endregion // convert attributes and variables}