0

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/

その下にネストされた返信を取得する方法を教えてもらえますか?だから立ち往生。ありがとう!

4

1 に答える 1

2

さて、私はあなたのために簡単なデモを作成することができました。[jsfiddleコードはこちら][1][1]:http: //jsfiddle.net/nickadeemus2002/qzNad/

私はそれをjsonデータ構造に基づいたいくつかの基本的なループで動作させています。コードの一部をリファクタリングする必要があるため、これはデモ目的のためだけです。ただし、データにアクセスする方法を確認できるように機能しています。

于 2012-06-16T07:00:00.183 に答える