如何用jquery读取json值? [英] how to read the json values with jquery?

查看:120
本文介绍了如何用jquery读取json值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的JSON响应就像这样 {items:[{s:2,f:host,m:hi .. :)},]}



我写了下面的代码来读取JSON数据。但没有得到任何价值。警报框也不起作用。如果有人请告诉我我错在哪里...



$ .ajax({



url:ChatHandler.aspx?action = chatheartbeat,

cache:false,

dataType:json,

成功:函数(数据){



$ .each(data.items,function(i,item){



if(item){//修复怪即ie bug



chatboxtitle = item.f;



alert (item.m);



}

});

});

解决方案

.ajax({



url:ChatHandler.aspx?action = chatheartbeat,

cache:false,

dataType:json,

成功:函数(数据){



.each(data.items,function(i,item){



if(item){// fix strange ie bug



chatboxtitle = item.f;



alert(item.m);



}

});

});


警告可能由以下原因之一起作用:



  • data.items 为空;然后是


中的函数

my JSON response is like this { "items":[{"s": "2","f": "host","m": "hi..:)"}, ] }

I wrote the following code to read the JSON data. but not getting the any value. alert box also not working. If any one please inform me where I did mistake ...

$.ajax({

url: "ChatHandler.aspx?action=chatheartbeat",
cache: false,
dataType: "json",
success: function (data) {

$.each(data.items, function (i, item) {

if (item) { // fix strange ie bug

chatboxtitle = item.f;

alert(item.m);

}
});
});

解决方案

.ajax({

url: "ChatHandler.aspx?action=chatheartbeat",
cache: false,
dataType: "json",
success: function (data) {


.each(data.items, function (i, item) {

if (item) { // fix strange ie bug

chatboxtitle = item.f;

alert(item.m);

}
});
});


Alert might not work by one of the following reasons:

  • data.items is empty; then the function in the


这篇关于如何用jquery读取json值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆