Extjs获取不到后台回传的json数据
前台Extjs代码:
Ext.onReady(function () {
var store = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({ url: "/WebService/test/tb_data.ashx" }),
reader: new Ext.data.JsonReader({
totalProperty: "results",
root: "jsonObjs"
},
[
{ name: 'user_name' },
{ name: 'user_id' },
{ name: 'ssyj' }
]
),
listeners: {
load: function () {
alert(store.getCount());
}
}
});
store.load();
});
后台代码:
public void ProcessRequest(HttpContext context)
{
context.Request.ContentEncoding = Encoding.GetEncoding("UTF-8");
context.Response.ContentEncoding = Encoding.GetEncoding("UTF-8");
context.Response.Charset = "UTF-8";
context.Response.ContentType = "text/plain";
string result = string.Empty;
string ygk_list = string.Empty;
string strSQL = string.Empty;
try
{
strSQL = string.Format(@"select tb_user.user_name,tb_fwcjqr.user_id,sum(tb_fwcjqr.htzj)as ssyj from tb_fwcjqr
inner join tb_user on tb_user.id = tb_fwcjqr.user_id
group by tb_user.user_name ,tb_fwcjqr.user_id");
DataTable dt = LTP.DBUtility.DbHelperSQL.Query(strSQL).Tables[0];
if (dt.Rows.Count > 0)
{
result = LTP.BLL.Ext_Json.DataTable2Json(dt);
}
else
{
result = "false";
}
}
catch
{
result = "error";
}
context.Response.Write(result);
}
返回的json字符串如下:
{"results":3,"jsonObjs":["user_name":"郑正英","user_id":"10","ssyj":"39569.0100"},"user_name":"王雪梅","user_id":"11","ssyj":"557619.9900"},"user_name":"张丹青","user_id":"12","ssyj":"116000.0000"},"user_name":"张海东","user_id":"13","ssyj":"1412742.9900"}]}
究竟是那里错了生成不了store数据.搞都我头都疼了.
[解决办法]
store = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: "/WebService/test/tb_data.ashx",
reader: new Ext.data.JsonReader({ totalProperty: "results", root: "jsonObjs" })////reader配置是proxy的,不是store的
}),
fields: [{ name: 'user_name' }, { name: 'user_id' }, { name: 'ssyj'}],
listeners: {
load: function () {
alert(store.getCount());
}
}
});