aspx返回JSON数据问题
当前我正在用ext搞个网站,但是用Ext.Grid时不知道怎么获取数据,现在我用的是JSON
下面是返回JSON格式数据的页面
private PublishList[] _pi;
protected void Page_Load(object sender, EventArgs e)
{
HSHBLL.Init();
if (Request["txtType"] != null || Request["contType"] != null)
{
string txtType = Request.QueryString["txtType"];
int contType = Int32.Parse(Request.QueryString["contType"]);
_pi = HSHBLL.GetPublishList(contType, txtType);
Response.ContentType = "application/x-json";
StringBuilder xml = new StringBuilder();
xml.Append("{\"data\":[");
for (int i = 0; i < _pi.Length; i++)
{
xml.AppendLine(ToJsonString(_pi[i].txtId, _pi[i].txtTitle, _pi[i].txtPublishDate));
}
xml.Append("],\"totalCount\":" + _pi.Length + "}");
Response.Write(xml);
}
else
{
Response.Redirect("Err.htm");
}
}
string ToJsonString(int txtid_, string txttitle_, DateTime publishdate_)
{
PublishList pl = new PublishList();
pl.txtId = txtid_;
pl.txtPublishDate = publishdate_;
pl.txtTitle = txttitle_;
return JavaScriptConvert.SerializeObject(pl);
}
//////读取json的代码
var ds = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: "List.aspx?txtType=" + escape("老人健康") + "&contType=2"
}),
reader: new Ext.data.JsonReader({
root: "data",
totalProperty: 'totalCount', //这里从url返回结果中读取记录总数
fields: [
{ name: 'txtId', mapping: 'txtId' },
{ name: 'txtTitle', mapping: 'txtTitle' },
{ name: 'txtPublishDate', mappgin: 'txtPublishDate', type: 'date', dateFormat: 'M j, Y' }
]
})
});
ds.load({
params: {
start: 0,
limit: 10
}
});
不知道为什么就是读不到数据,不知道是JSON格式不对还是什么问题