.cs文件的主要代码:
publicclassUser_List //这个类是对应是Extjs的Grid的field里面的,field有几项就写几项{
publicintVoteID =0;
publicstringVoteName ="";
publicDateTime SystemDateTime =DateTime.Parse(DateTime.Today.AddDays(1).ToString("yyyy-MM-dd"));
publicDateTime EndTime =DateTime.Parse(DateTime.Today.AddDays(1).ToString("yyyy-MM-dd"));
publicstringIsStatus ="禁用";
publicintSubmitTimes =0;
}
protectedListlst =newList();//创建数组protectedUser_List userlst =newUser_List();//定义的类设置对象for(inti =0; i
userlst =newUser_List();//每次循环就新定义对象,不然复制的都是同一组值,每次覆盖原来复制的(这个很重要)
userlst.VoteID =(int)dt.Rows[i]["VoteID"];
userlst.VoteName =dt.Rows[i]["VoteName"].ToString();
userlst.SystemDateTime =DateTime.Parse(dt.Rows[i]["SystemDateTime"].ToString());
userlst.EndTime =DateTime.Parse(dt.Rows[i]["EndTime"].ToString());
userlst.IsStatus =dt.Rows[i]["IsStatus"].ToString();
userlst.SubmitTimes =(int)dt.Rows[i]["SubmitTimes"];
lst.Add(userlst);
}
//下面的代码就是将数据库的值转化为Json的主要代码JavaScriptSerializer java =newJavaScriptSerializer();
StringBuilder sb =newStringBuilder();
java.Serialize(lst, sb);
stringjson =sb.ToString();
<