// Able serialization
Public string getSendDetailQuery (DateTime timeS, DateTime timeE, string sccount)
{
Try
{
SmsOperate so = new SmsOperate ();
// Obtain dt
DataTable dtt = so. getSendDetailQuery (timeS, timeE, sccount );
JavaScriptSerializer serializer = new JavaScriptSerializer ();
String aaa = Serialize (dtt, false); // datatable cannot be serialized directly. This is a serialization method.
Return "0:" + aaa;
}
Catch (Exception e)
{
Return "-1" + e. Message;
}
}
/// <Summary> serialization Method
/// No paging is required
/// </Summary>
/// <Param name = "dt"> </param>
/// <Param name = "flag"> false </param>
/// <Returns> </returns>
Public string Serialize (DataTable dt, bool flag)
{
JavaScriptSerializer serializer = new JavaScriptSerializer ();
List <Dictionary <string, object> list = new List <Dictionary <string, object> ();
Foreach (DataRow dr in dt. Rows)
{
Dictionary <string, object> result = new Dictionary <string, object> ();
Foreach (DataColumn dc in dt. Columns)
{
Result. Add (dc. ColumnName, dr [dc]. ToString ());
}
List. Add (result );
}
Return serializer. Serialize (list );;
}
// Deserialize www.2cto.com
Public DataTable getSendDetailTest ()
{
DataTable dtb = new DataTable ();
// Get the serialization result aaa
String aaa = getSendDetailQuery (Convert. ToDateTime ("00:00:00"), Convert. ToDateTime ("23:59:59"), "wangsub1 ");
If (aaa. Substring (0, 1) = "0 ")
{
Try
{
JavaScriptSerializer serializer = new JavaScriptSerializer ();
// Var obj = serializer. DeserializeObject (aaa); // deserialization
ArrayList dic = serializer. Deserialize <ArrayList> (aaa); // Deserialize the ArrayList type
If (dic. Count> 0)
{
Foreach (Dictionary <string, object> drow in dic)
{
If (dtb. Columns. Count = 0)
{
Foreach (string key in drow. Keys)
{
Dtb. Columns. Add (key, drow [key]. GetType (); // Add the dt column name
}
}
DataRow row = dtb. NewRow ();
Foreach (string key in drow. Keys)
{
Row [key] = drow [key]; // Add a column Value
}
Dtb. Rows. Add (row); // Add a row
}
}
}
Catch (Exception e)
{
//
}
}
Else
{
//
}
Return dtb;
}
From SYZ_YUMEIZHOU_YY