0

我试图弄清楚如何解析我使用graphPath:@"me/home".

我假设从返回的数据

FBRequest *request = [[FBRequest alloc] initWithSession:FBSession.activeSession
                                              graphPath:@"me/home"];

不需要解析,我只需要通过字典键提取数据,我发现这很混乱。我试图将数据放入 tableview 中,基本上显示来自 Facebook 的用户新闻提要。这是返回的数据片段:

"data": [
    {
        "id": "1156410856_4453627016238",
        "from": {
            "name": "Abbi ☆ Mathews",
            "id": "1156410856"
        },
        "message": "Aalllllllll over this tonight.......be there....gonna be booooom ting!",
        "picture": "http://photos-a.ak.fbcdn.net/hphotos-ak-snc6/185169_4453626736231_812066502_s.jpg",
        "link": "http://www.facebook.com/photo.php?fbid=4453626736231&set=a.1166926850788.88722.1156410856&type=1&relevant_count=1",
        "icon": "http://static.ak.fbcdn.net/rsrc.php/v2/yx/r/og8V99JVf8G.gif",
        "actions": [
            {
                "name": "Comment",
                "link": "http://www.facebook.com/1156410856/posts/4453627016238"
            },
            {
                "name": "Like",
                "link": "http://www.facebook.com/1156410856/posts/4453627016238"
            }
        ],
        "privacy": {
            "description": "Friends; Except: Restricted",
            "value": "ALL_FRIENDS"
        },
        "type": "photo",
        "object_id": "4453626736231",
        "application": {
            "name": "Facebook for Android",
            "namespace": "fbandroid",
            "id": "350685531728"
        },
        "created_time": "2012-08-25T14:08:11+0000",
        "updated_time": "2012-08-25T14:08:11+0000",
        "comments": {
            "count": 0
        }
    },
    {
        "id": "7147617470_10150998196922471",
        "from": {
            "name": "The Fratellis",
            "category": "Musician/band",
            "id": "7147617470"
        },
        "picture": "http://platform.ak.fbcdn.net/www/app_full_proxy.php?app=123966167614127&v=1&size=z&cksum=77469f27ebc292a58b3ee8ffb8183582&src=https%3A%2F%2Fd12nfv3nknyhzq.cloudfront.net%2Fimages%2Fartists%2F1208090326852218_medium.jpg",
        "link": "http://www.bandsintown.com/event/5469167/facebook_rsvp?artist=The+Fratellis&came_from=90",
        "name": "Next Month: The Fratellis @ Academy in Oxford, United Kingdom",
        "caption": "Saturday, September 22, 2012 at 7:00pm",
        "properties": [
            {
                "name": "Tickets",
                "text": "http://bnds.in/Nq9prK",
                "href": "http://www.bandsintown.com/event/5469167/buy_tickets?affil_code=fb_7147617470_auto_promote_month_before_targeted&artist=The+Fratellis"
            },
            {
                "name": "More Tour Dates",
                "text": "http://bnds.in/O9NLwd",
                "href": "http://www.bandsintown.com/TheFratellis/facebookapp?came_from=90"
            }
        ],
        "icon": "http://photos-b.ak.fbcdn.net/photos-ak-snc7/v85006/251/123966167614127/app_2_123966167614127_7663.gif",
        "actions": [
            {
                "name": "Comment",
                "link": "http://www.facebook.com/7147617470/posts/10150998196922471"
            },
            {
                "name": "Like",
                "link": "http://www.facebook.com/7147617470/posts/10150998196922471"
            },
            {
                "name": "RSVP",
                "link": "http://www.bandsintown.com/event/5469167/facebook_rsvp?artist=The+Fratellis&came_from=90"
            }
        ],
        "privacy": {
            "description": "United Kingdom",
            "value": "CUSTOM"
        },
        "type": "link",
        "application": {
            "name": "Bandsintown",
            "namespace": "concertsbybit",
            "id": "123966167614127"
        },
        "created_time": "2012-08-25T14:06:39+0000",
        "updated_time": "2012-08-25T14:14:01+0000",
        "likes": {
            "data": [
                {
                    "name": "Derek Moore",
                    "id": "536043117"
                },
                {
                    "name": "Louise Berry",
                    "id": "1310689257"
                },
                {
                    "name": "Jack Barber",
                    "id": "100002857426027"
                },
                {
                    "name": "Becky Hoddinott",
                    "id": "100000168277953"
                }
            ],
            "count": 8
        },
        "comments": {
            "data": [
                {
                    "id": "7147617470_10150998196922471_22699715",
                    "from": {
                        "name": "Becky Hoddinott",
                        "id": "100000168277953"
                    },
                    "message": "Yesssssss! <3",
                    "created_time": "2012-08-25T14:14:01+0000"
                }
            ],
            "count": 1
        }
    },
    {

我一直试图把它放到一个表格视图中,但是 UILabels 只是空白,所以我用什么键来让它工作?

继承人所有代码:

-(void)sendRequests {
  FBRequestConnection *connection = [[FBRequestConnection alloc] init];
  FBRequest *request = [[FBRequest alloc] initWithSession:FBSession.activeSession
                                                graphPath:@"me/home"];

  [connection addRequest:request completionHandler:
    ^(FBRequestConnection *connection, id result, NSError *error) {
      if (!error &&  result) {
        NSLog(@"Pre Parsed Data = %@", result);
        NSArray *arrayRsult = [result objectForKey:@"data"];

        for (_FBData in arrayRsult){
          [self.tableView reloadData];
        }
      } else if (error) {             
        NSLog(@"Error Fetching Data = %@", error);
      }
    }];

  [connection start];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:  (NSIndexPath *)indexPath {
  static NSString *CellIdentifier = @"Cell";
  FaceBookCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  if (cell == nil) {
    cell = [[FaceBookCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];        
    NSLog(@"Intialise Cell");
  }

  NSMutableDictionary *fbText = [_FBData objectAtIndex:indexPath.row];
  NSString *name = [[fbText objectForKey:@"from"] objectForKey:@"name"];
  NSString *dateCreated = [fbText objectForKey:@"created_time"];
  NSString *message = [fbText objectForKey:@"message"];

  [cell.name setText:name];
  [cell.message setText:message];
  [cell.time setText:dateCreated];

  NSLog(@"Names = %@", name);

  return cell;
}
4

0 回答 0