public static string ToJsonForHandle <T>(int userId, int gridId, IList <T> list, int currentPage, int numPage, int totalRow) where T : new() { CGridColumnConfig[] grid = CGrid.GetColumnNameGrid(userId, gridId); StringBuilder strRet = new StringBuilder(); strRet.AppendFormat("{{\"currpage\":\"{0}\",\"totalpages\":\"{1}\",\"totalrecords\":\"{2}\",\"invdata\":[", currentPage, numPage, totalRow); for (int j = 0; j < list.Count; j++) { string strObj = ""; for (int i = 0; i < grid.Length; i++) { string modelName = grid[i].Name; string value = ""; PropertyInfo propertyInfo = list[j].GetType().GetProperty(grid[i].DataMappingName); if (propertyInfo != null && propertyInfo.GetValue(list[j], null) != null) { /*if (list[j][grid[i].DataMappingName].GetType() == DateTime.Now.GetType()) * { * value = "\"" + FormatDate((DateTime)list[j][grid[i].DataMappingName], "yyyy-MM-dd HH:mm:ss") + "\""; * } * else * {*/ value = Newtonsoft.Json.JsonConvert.SerializeObject(propertyInfo.GetValue(list[j], null), new IsoDateTimeConverter()); //} } else { value = "\"\""; } string strFormatHandle = "\"{0}\":{1}"; strObj += string.Format(strFormatHandle, modelName, value); if (i < grid.Length - 1) { strObj += ","; } } strRet.Append("{" + strObj + "}"); if (j < list.Count - 1) { strRet.Append(","); } } strRet.Append("]}"); return(strRet.ToString()); }