繁体   English   中英

用jquery解析嵌套的json结果 - 例子里面

[英]parsing nested json results with jquery - example inside

jsFiddle: http//jsfiddle.net/FRQ9b/

使用reddit的json结果。 这是我用3个回复(嵌套)创建的示例帖子。

?([
     {
        "kind":"Listing",
        "data":{
           "modhash":"",
           "children":[
              {
                 "kind":"t3",
                 "data":{
                    "domain":"self.testapiarena",
                    "banned_by":null,
                    "media_embed":{

                    },
                    "subreddit":"testapiarena",
                    "selftext_html":"<!-- SC_OFF --><div class=\"md\"><p>Example of selfpost text</p>\n</div><!-- SC_ON -->",
                    "selftext":"Example of selfpost text",
                    "likes":null,
                    "link_flair_text":null,
                    "id":"v4bux",
                    "clicked":false,
                    "title":"testing nested comments",
                    "num_comments":3,
                    "score":1,
                    "approved_by":null,
                    "over_18":false,
                    "hidden":false,
                    "thumbnail":"",
                    "subreddit_id":"t5_2ub3u",
                    "edited":false,
                    "link_flair_css_class":null,
                    "author_flair_css_class":null,
                    "downs":0,
                    "saved":false,
                    "is_self":true,
                    "permalink":"/r/testapiarena/comments/v4bux/testing_nested_comments/",
                    "name":"t3_v4bux",
                    "created":1339833041.0,
                    "url":"http://www.reddit.com/r/testapiarena/comments/v4bux/testing_nested_comments/",
                    "author_flair_text":null,
                    "author":"elzi",
                    "created_utc":1339807841.0,
                    "media":null,
                    "num_reports":null,
                    "ups":1
                 }
              }
           ],
           "after":null,
           "before":null
        }
     },
     {
        "kind":"Listing",
        "data":{
           "modhash":"",
           "children":[
              {
                 "kind":"t1",
                 "data":{
                    "body":"This is a parent comment",
                    "edited":false,
                    "subreddit_id":"t5_2ub3u",
                    "author_flair_css_class":null,
                    "created":1339833054.0,
                    "replies":{
                       "kind":"Listing",
                       "data":{
                          "modhash":"",
                          "children":[
                             {
                                "kind":"t1",
                                "data":{
                                   "body":"This is one comments below the parent level",
                                   "edited":false,
                                   "subreddit_id":"t5_2ub3u",
                                   "author_flair_css_class":null,
                                   "created":1339833067.0,
                                   "replies":{
                                      "kind":"Listing",
                                      "data":{
                                         "modhash":"",
                                         "children":[
                                            {
                                               "kind":"t1",
                                               "data":{
                                                  "body":"A comment below the first child.",
                                                  "edited":false,
                                                  "subreddit_id":"t5_2ub3u",
                                                  "author_flair_css_class":null,
                                                  "created":1339833090.0,
                                                  "replies":"",
                                                  "banned_by":null,
                                                  "downs":0,
                                                  "author":"elzi",
                                                  "created_utc":1339807890.0,
                                                  "body_html":"<div class=\"md\"><p>A comment below the first child.</p>\n</div>",
                                                  "link_id":"t3_v4bux",
                                                  "parent_id":"t1_c517ue3",
                                                  "approved_by":null,
                                                  "likes":null,
                                                  "author_flair_text":null,
                                                  "id":"c517ujo",
                                                  "subreddit":"testapiarena",
                                                  "num_reports":null,
                                                  "ups":1,
                                                  "name":"t1_c517ujo"
                                               }
                                            }
                                         ],
                                         "after":null,
                                         "before":null
                                      }
                                   },
                                   "banned_by":null,
                                   "downs":0,
                                   "author":"elzi",
                                   "created_utc":1339807867.0,
                                   "body_html":"<div class=\"md\"><p>This is one comments below the parent level</p>\n</div>",
                                   "link_id":"t3_v4bux",
                                   "parent_id":"t1_c517uas",
                                   "approved_by":null,
                                   "likes":null,
                                   "author_flair_text":null,
                                   "id":"c517ue3",
                                   "subreddit":"testapiarena",
                                   "num_reports":null,
                                   "ups":1,
                                   "name":"t1_c517ue3"
                                }
                             }
                          ],
                          "after":null,
                          "before":null
                       }
                    },
                    "banned_by":null,
                    "downs":0,
                    "author":"elzi",
                    "created_utc":1339807854.0,
                    "body_html":"<div class=\"md\"><p>This is a parent comment</p>\n</div>",
                    "link_id":"t3_v4bux",
                    "parent_id":"t3_v4bux",
                    "approved_by":null,
                    "likes":null,
                    "author_flair_text":null,
                    "id":"c517uas",
                    "subreddit":"testapiarena",
                    "num_reports":null,
                    "ups":1,
                    "name":"t1_c517uas"
                 }
              }
           ],
           "after":null,
           "before":null
        }
     }
  ])

这是一个jsfiddle,我已经走了多远: http//jsfiddle.net/FRQ9b/

谁能告诉我如何获得下面的嵌套回复? 所以卡住了。 谢谢!

好的,我设法为你创建了一个快速演示。 你可以看看这里的[jsfiddle代码。] [1] [1]: http//jsfiddle.net/nickadeemus2002/qzNad/

我让它使用基于json数据结构的一些基本循环。 这只是为了演示目的,因为你必须重构一些代码。 但是,我有它的工作,所以你可以看到如何访问数据。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM