使用jQuery解析JSON [英] Parse JSON with jQuery

查看:101
本文介绍了使用jQuery解析JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用jQuery解析以下JSON并获取每个id值。任何人都可以建议吗?

I am trying to parse the following JSON with jQuery and get each id value. Can anyone advise?

[
{
    "id": "1",
    "name": "Boat"
},
{
    "id": "2",
    "name": "Cable"
}

]

到目前为止,我有:

$.each(test, function(i,item){
   alert(item);
   });

但这只列出了每个值。我怎么能

But that simply lists every value. How can I

推荐答案

这将列出数组中的每个对象,以获取 id 您所在的属性,只需添加 .id ,就像这样:

That'll list every object in your array, to get the id property of the one you're on, just add .id like this:

$.each(test, function(i,item){
  alert(item.id);
});

这篇关于使用jQuery解析JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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