簡體   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