javascript - 使用 jQuery 解析 JSON

标签 javascript jquery json

我正在尝试使用 jQuery 解析以下 JSON 并获取每个 id 值。谁能建议?

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

]

到目前为止我有:

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

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

最佳答案

这将列出数组中的每个对象,要获取你所在对象的 id 属性,只需添加 .id 如下所示:

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

关于javascript - 使用 jQuery 解析 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4569230/

相关文章:

javascript - 使用 HTML5 的跨平台移动应用程序

json - 在Apache Pig中加载Json数据时出错

javascript - 错误:How can I get the params from controller without reloading the browser?

javascript - AngularJS:如何在配置阶段使用 $http

javascript - 使用 ng-view 并按需加载 Controller

java - 如何判断InputStream中是否包含JSON数据?

java - Jackson - 在不使用 JsonSerializer 和 BeanSerializerModifier 的情况下定义空字段

javascript - jquery中options和originalOptions的区别

XUL 的 jQuery?

javascript - 以编程方式单击输入元素