DataTable searchTable = _createPageManager.SearchSql(searchSql, searchField); DataRow[] drArr = searchTable.AsEnumerable().Skip((pageIndex - 1) * pageSize).Take(pageSize).ToArray();
/// <summary> /// DataRow[] 转换成Json格式 /// </summary> /// <param name="drArr"></param> /// <returns></returns> public static string DataRowToJson(DataRow[] drArr) { StringBuilder jsonBuilder = new StringBuilder(); jsonBuilder.Append("["); if (drArr.Length > 0) { foreach (DataRow dr in drArr) { jsonBuilder.Append("{"); for (int drIndex = 0; drIndex < dr.ItemArray.Length; drIndex++) { jsonBuilder.AppendFormat("\"{0}\":\"{1}\",", dr.Table.Columns[drIndex].ColumnName, dr[drIndex].ToString().Replace('"', '‘').Replace("'","‘").Trim()); } jsonBuilder.Remove(jsonBuilder.Length - 1, 1); jsonBuilder.Append("},"); } jsonBuilder.Remove(jsonBuilder.Length - 1, 1); } jsonBuilder.Append("]"); return jsonBuilder.ToString(); }