1 /// <summary>2 ///convert a DataTable to JSON3 /// </summary>4 /// <param name= "DTB" >Dt</param>5 /// <returns>JSON string</returns>6 Public stringDtb2json (DataTable dtb)7 {8JavaScriptSerializer JSS =NewJavaScriptSerializer ();9System.Collections.ArrayList dic =NewSystem.Collections.ArrayList ();Ten foreach(DataRow DrinchDTB. Rows) One { Asystem.collections.generic.dictionary<string,Object> Drow =Newsystem.collections.generic.dictionary<string,Object>(); - foreach(DataColumn DCinchDTB. Columns) - { the Drow. ADD (DC. ColumnName, DR[DC. ColumnName]); - } - DiC. ADD (drow); - + } - //Serialization of + stringJsonstr=JSS. Serialize (DIC); AJsonstr = System.Text.RegularExpressions.Regex.Replace (Jsonstr,@"\\/date\ ((\d+) \) \\/", match = at { -DateTime dt =NewDateTime (1970,1,1); -DT = dt. Addmilliseconds (Long. Parse (match. groups[1]. Value)); -DT =dt. ToLocalTime (); - returnDt. ToString ("YYYY-MM-DD HH:mm:ss"); - }); in returnJsonstr; -}
C#datatable2json (Time format)