设为首页 加入收藏

TOP

Json读取的方式辨析
2014-11-24 14:57:52 来源: 作者: 【 】 浏览:32
Tags:Json 读取 方式 辨析

读取一:



$.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);
java scriptSerializer jss = new java scriptSerializer();
Response.Write(jss.Serialize(points));



看到没有。它是TB_MonitoringPoint的一个数组!所以当然要用$.each!


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇SSH+Android之Struts 下一篇Eclipse helios 配置Struts2图解

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: