コード例 #1
0
ファイル: JsonHelper.cs プロジェクト: zhangjiecxy/zhangjie
 /// <summary>
 /// 表格返回JSON
 /// </summary>
 /// <param name="dt">数据行</param>
 /// <param name="pageIndex">当前页面</param>
 /// <param name="pqGrid_Sort">要显示字段</param>
 /// <param name="count"></param>
 /// <returns></returns>
 public static string PqGridPageJson <T>(IList list, int pageIndex, string pqGrid_Sort, int count)
 {
     try
     {
         string[]      Sort_Field = pqGrid_Sort.Split(',');
         StringBuilder sb         = new StringBuilder();
         sb.Append("{");
         sb.Append("\"totalRecords\": " + count + ",");
         sb.Append("\"curPage\": " + pageIndex + ",");
         sb.Append("\"data\": [");
         if (list.Count > 0)
         {
             foreach (T entity in list)
             {
                 Hashtable ht = HashtableHelper.GetModelToHashtable <T>(entity);
                 sb.Append("[");
                 foreach (string item in Sort_Field)
                 {
                     sb.Append("\"");
                     if (ht[item] != null && ht[item] != DBNull.Value && ht[item].ToString() != "")
                     {
                         sb.Append(ht[item]);
                     }
                     else
                     {
                         sb.Append("");
                     }
                     sb.Append("\",");
                 }
                 sb = sb.Remove(sb.Length - 1, 1);
                 sb.Append("],");
             }
             sb = sb.Remove(sb.Length - 1, 1);
         }
         sb.Append("]");
         sb.Append("}");
         return(sb.ToString());
     }
     catch (Exception ex)
     {
         return("");
     }
 }
コード例 #2
0
ファイル: JsonHelper.cs プロジェクト: zhangjiecxy/zhangjie
 /// <summary>
 /// 表格返回JSON
 /// </summary>
 /// <param name="pqGrid_Sort">要显示字段</param>
 /// <param name="count"></param>
 /// <returns></returns>
 public static string PqGridJson <T>(IList list, string pqGrid_Sort)
 {
     try
     {
         string[]      Sort_Field = pqGrid_Sort.Split(',');
         StringBuilder sb         = new StringBuilder();
         if (list.Count > 0)
         {
             sb.Append("[");
             foreach (T entity in list)
             {
                 Hashtable ht = HashtableHelper.GetModelToHashtable <T>(entity);
                 sb.Append("[");
                 foreach (string item in Sort_Field)
                 {
                     sb.Append("\"");
                     if (ht[item] != null && ht[item] != DBNull.Value && ht[item].ToString() != "")
                     {
                         sb.Append(ht[item]);
                     }
                     else
                     {
                         sb.Append("");
                     }
                     sb.Append("\",");
                 }
                 sb = sb.Remove(sb.Length - 1, 1);
                 sb.Append("],");
             }
             sb = sb.Remove(sb.Length - 1, 1);
             sb.Append("]");
         }
         return(sb.ToString());
     }
     catch (Exception ex)
     {
         return("");
     }
 }