Ajax reduces network content transmission asynchronously, while JSON reduces the transmitted content to pure data. Then, jquery's built-in Ajax function is used to directly obtain data in JSON format; bind the client directly to the data control to achieve optimal performance.
# Region datatable converted to JSON format
/// <Summary>
/// Datatable converted to JSON format
/// </Summary>
/// <Param name = "DT"> </param>
/// <Returns> </returns>
Public static string datatable2json (datatable DT)
{
Stringbuilder jsonbuilder = new stringbuilder ();
Jsonbuilder. append ("{\"");
Jsonbuilder. append (Dt. tablename. tostring ());
Jsonbuilder. append ("\":[");
For (INT I = 0; I <DT. Rows. Count; I ++)
{
Jsonbuilder. append ("{");
For (Int J = 0; j <DT. Columns. Count; j ++)
{
Jsonbuilder. append ("\"");
Jsonbuilder. append (Dt. Columns [J]. columnname );
Jsonbuilder. append ("\":\"");
Jsonbuilder. append (Dt. Rows [I] [J]. tostring ());
Jsonbuilder. append ("\",");
}
Jsonbuilder. Remove (jsonbuilder. Length-1, 1 );
Jsonbuilder. append ("},");
}
Jsonbuilder. Remove (jsonbuilder. Length-1, 1 );
Jsonbuilder. append ("]");
Jsonbuilder. append ("}");
Return jsonbuilder. tostring ();
}
# Convert endregion datatable to JSON format
# Region dataset converted to JSON format
/// <Summary>
/// Convert dataset to JSON format
/// </Summary>
/// <Param name = "ds"> dataset </param>
/// <Returns> </returns>
Public static string dataset2json (Dataset DS)
{
Stringbuilder JSON = new stringbuilder ();
Foreach (datatable DT in DS. Tables)
{
JSON. append ("{\"");
JSON. append (Dt. tablename );
JSON. append ("\":");
JSON. append (datatable2json (DT ));
JSON. append ("}");
}
Return JSON. tostring ();
}
# Endregion