Json读取的方式介绍
发布时间:2021-12-18 14:18:04 所属栏目:教程 来源:互联网
导读:读取一: $.ajax({ type:GET, dataType:json, data:{id:json[i].ID}, async:false, url:../../Ajax/CalculateLamps.aspx, success:function(data){ redlamp+=parseInt(data[0][red],10); greenlamp+=parseInt(data[0][green],10); yellowlamp+=parseInt(data
|
读取一: $.ajax({ type:"GET", dataType:"json", data:{id:json[i].ID}, async:false, url:"../../Ajax/CalculateLamps.aspx", success:function(data){ redlamp+=parseInt(data[0]["red"],10); greenlamp+=parseInt(data[0]["green"],10); yellowlamp+=parseInt(data[0]["yellow"],10); } }); 我们来看看CalculateLamps返回的是什么? result = "[{green:'" + NumGreenLamp.ToString() + "',red:'" + NumRedLamp.ToString() + "',yellow:'" + NumYellowLamp.ToString() + "'}]"; 看到了吗?每次发一次请求,他就返回一次 "[{green:'" + NumGreenLamp.ToString() + "',red:'" + NumRedLamp.ToString() + "',yellow:'" + NumYellowLamp.ToString() + "'}]"; 所以他每一次永远只返回一条,所以data[0]["red"]这种方法。 读取二: $.getJSON( "../../Ajax/GetPoints.aspx", { ID: item.value }, function(json, status) { if (status == "success") { if (json == null) { alert("该部门没有监控点!"); } else { $.each(json, function(i) { json[i]......... } } }); 我们来看看GetPoints.aspx这个页面返回的是什么? var points = (from p in dc.TB_MonitoringPoint where p.CompanyID == intid select p).Skip(0 * pageSize).Take(pageSize); JavaScriptSerializer jss = new JavaScriptSerializer(); Response.Write(jss.Serialize(points)); 看到没有。它是TB_MonitoringPoint的一个数组!所以当然要用$.each! ![]() (编辑:开发网_郴州站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |



浙公网安备 33038102330466号