【问题标题】:parsing a jquery/javascript object into an array or useable data将 jquery/javascript 对象解析为数组或可用数据
【发布时间】:2014-11-25 14:50:04
【问题描述】:

当我执行$.getJSON:

$.getJSON("http://localhost.com", function(data) {
  console.log(data)
  console.log(data.posts);
});    

这就是我得到的 - 如何将帖子数组转换为变量或可用格式?我试过了

console.log(data.posts)

没有运气。

【问题讨论】:

  • 使用点符号。 data.posts.whateverYouWant
  • 我不确定我是否理解这个问题...您只是在打印数组 - 我看不到您正在为变量分配任何内容...

标签: jquery json parsing javascript-objects


【解决方案1】:

data.posts 是你想要的。它是一个包含名为posts 的数组的对象。要获得它,请使用

var posts = data.posts.posts;

【讨论】:

  • boom...那个简单的 var posts = data.posts[0].author.name;
猜你喜欢
  • 2018-10-18
  • 2016-08-17
  • 2016-09-29
  • 1970-01-01
  • 2014-12-02
  • 2023-03-22
  • 2020-05-02
  • 2011-08-17
  • 1970-01-01
相关资源
最近更新 更多