1 /// <summary> 2 /// 报警信息分页 3 /// </summary> 4 /// <param name="pm"></param> 5 /// <returns></returns> 6 public ActionResult AlarmQuery(PageModel pm) 7 { 8 9 Geostatic.BLL.AlarmInfo bllmp = new Geostatic.BLL.AlarmInfo(); 10 string sqlstr = ""; 11 sqlstr += "AlarmTime between DATEADD(DAY,-1,GETDATE()) and GETDATE() and AlarmType>0"; 12 List<Geostatic.Model.AlarmInfo> lsmp = bllmp.GetModelList(sqlstr); 13 14 List<Geostatic.Model.AlarmInfo> lsAlarmInfo = new List<Geostatic.Model.AlarmInfo>(); 15 16 //起始页 17 int startPage = pm.rows * (pm.page - 1); 18 //结束页 19 int endPage = pm.rows * pm.page; 20 if (endPage >=lsmp.Count) 21 { 22 endPage = lsmp.Count; 23 } 24 25 //遍历循环 26 for (int i = startPage; i < endPage; i++) 27 { 28 Geostatic.Model.AlarmInfo alarm = new Geostatic.Model.AlarmInfo(); 29 alarm = lsmp[i]; 30 lsAlarmInfo.Add(alarm); 31 32 } 33 var result = new { total = lsmp.Count, rows = lsAlarmInfo }; 34 return base.Json(result, JsonRequestBehavior.AllowGet); 35 36 }
获取数据,josn显示到页面,结果日期发生了变化:
/Date(1359426184000)/
前台部分:
<table id="dg" class="easyui-datagrid"> <thead> <tr> <th field="MineName">矿井名称</th> <th field="DetectorPlace">探测器安装位置</th> <th field= "Channel" >通道</th> <th field="AlarmType">报警类型</th> <th field="AlarmTime">报警时间</th> <th field="AlarmValue">报警值</th> </tr> </thead> </table>
求教哪为大仙指点一下,小弟对josn不太熟悉,请教一下,感激不尽,拜托了。
josn ?是JSON吧? 我就说说如何序列化和反序列化Json吧!
首先有这么一个类:
public class Book
{
public string BookID { get; set; }
public DateTime PublishDate { get; set; }
public decimal Price { get; set; }
}
序列化:
Book book= new Book() { BookID = "12111", PublishDate = DateTime.Parse("2012-2-1 22:12:11"), Price = 433.12M };
JavaScriptSerializer ser = new JavaScriptSerializer();
string jsonStr=ser.Serialize(book);
反序列化
这是一个符合Json格式的字符串:
string jsonBook1 = "[{'BookID':'123', 'PublishDate':'2011-1-2', 'Price':23.5},{'BookID':'123', 'PublishDate':'2011-1-2', 'Price':23.5}]";
Book book=(Book) ser.Deserialize(jsonBook1,typeof(Book));
在工作中也会遇到这个问题,解决办法:
1):在对象中加入一个字段,get{ return _this.attr.ToString();}
2):在js中创建一个function,去解析/Date(1359426184000)/这种格式。
function jsonDateFormat(jsonDate) {//json日期格式转换为正常格式 try { var date = new Date(parseInt(jsonDate.replace("/Date(", "").replace(")/", ""), 10)); var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1; var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate(); var hours = date.getHours(); var minutes = date.getMinutes(); var seconds = date.getSeconds(); var milliseconds = date.getMilliseconds(); return date.getFullYear() + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds; } catch (ex) { return ""; } }希望能帮到你。
我是直接在后台把日期转换为字符串的,那么前台js就不用处理了。
= =偶尔自己拼一段Json的路过。