首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >映射深度json

映射深度json
EN

Stack Overflow用户
提问于 2012-03-11 00:45:08
回答 1查看 373关注 0票数 0

如何映射这个json ?,我已经尝试在每个json上使用多个参数,但仍然无法获得数据。

代码语言:javascript
运行
复制
{ 
  "data" : { 
      "after" : "t3_qp79c",
      "before" : null,
      "children" : [ { 
            "data" : { "url" : "http://imgur.com/c0COJ" },
            "kind" : "t3"
      } ],
      "modhash" : ""
  },
  "kind" : "Listing"
}

我的javascript代码

代码语言:javascript
运行
复制
$.getJSON(reddit_api_url,function(data) {
  $.each(data.children['data'], function(i, reddit) {
    // Uncomment line below to show tweet data in Fire Bug console
    // Very helpful to find out what is available in the tweet objects
  //  console.log(reddit);

    // Before we continue we check that we got data

        console.log(i+' : '+ reddit );
      // Build the html string for the current tweet
      var tweet_html = reddit.url;


      // Append html string to tweet_container div
      $('#tweet_container').append(tweet_html);

  });
}

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-03-11 00:47:06

返回的数据具有自己的data属性,因此您需要...

代码语言:javascript
运行
复制
data.data.children[0]['data']

...to获取最里面的数据。

如果你在迭代children,那么你应该把它传递给$.each...

代码语言:javascript
运行
复制
$.each(data.data.children, function(i, obj) {
    console.log(obj.data.url);
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9648205

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档