這是推動我瘋狂,所以任何幫助將是真棒:jgGrid不顯示JSON數據
我的HTML是如下:
<asp:Content ID="Content3" ContentPlaceHolderID="Content" runat="server" class="MainLoginScreen">
<table id="StudyTable"></table>
<div id="StudiesPager"></div>
</asp:Content>
我的JavaScript如下:
<script language="javascript" type="text/javascript">
$(document).ready(function() {
$("#StudyTable").jqGrid({
url: '/StudyManager/GetStudyTable.aspx',
datatype: "json",
mtype:"GET",
colNames: ['Name', 'URL', 'Creation Date', 'Description', 'Status'],
colModel:[
{ name: 'Name', width: 200},
{ name: 'URL', width: 100 },
{ name: 'Creation_Date', width: 300},
{ name: 'Description', width: 200 },
{ name: 'Status', width: 200}
],
rowNum:10,
rowList:[10,20,30],
viewrecords: true,
sortname: 'Name',
sortorder: "asc",
pager: $('#StudiesPager'),
imgpath: '/Content/Images',
jsonReader: {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: true,
cell: "cell",
id: "id"
},
width: 800,
height: 400
});
});
</script>
和我的cs碼是:
protected void Page_Load(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
sb.Append("{'total':1,");
sb.Append("'page':'1',");
sb.Append("'records':'1',");
sb.Append("'rows': [");
sb.Append("{ 'id':'123', 'cell':['abc','abc','abc','abc','abc']}");
sb.Append("]}");
Response.Clear();
Response.StatusCode = 200;
Response.Write(sb.ToString());
Response.End();
}
表和尋呼機顯示完美,但沒有數據呈現到表中。 從我的CS返回的JSON似乎是正確的格式:
{'total':1,'page':'1','records':'1','rows': [{ 'id':'123', 'cell'['abc','abc','abc','abc','abc']}]}
但沒有數據顯示在網格中。
到JSON例如,應該更好地使用一些標準序列化程序,而不是手動JSON序列化:'ScriptSerializer.Serialize'或'DataContractJsonSerializer.WriteObject'。你也可以從http://json.codeplex.com/使用Json.net。 – Oleg 2010-07-02 10:57:52