这让我 疯狂 ,所以任何帮助都会很棒:
我的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']}]}
但网格中没有显示任何数据。
答案 0 :(得分:2)
您还可以创建类似的内容:
public class JqGridJsonData
{
public int Total {get;set;}
public int Page {get;set;}
etc
}
用Json.NET将其序列化为json http://james.newtonking.com/pages/json-net.aspx
答案 1 :(得分:1)
在可能导致问题的所有事情中 - 这是单引号。 JSON似乎不允许“单词”,而是需要“单词”。
所以来自cs的输出json应该是:
{"total":"1","page":"1","records":"1","rows": [{ "id":"123", "cell"["abc","abc","abc","abc","abc"]}]}