0

我正在获取我的数据,但似乎每次发现我的“可保留”=1 时,数据都会在 NSLog 中发布;我认为这应该只发布一次,当我在表格视图单元格中显示它时,它会发布多次吗?这是我的 NSLog:

2012-08-31 11:35:39.682 GBSB[2168:15b03] These are the times avail: (
)
2012-08-31 11:35:39.683 GBSB[2168:15b03] These are the times avail: (
    "2012-08-31 08:00:00 America/Los_Angeles"
)
2012-08-31 11:35:39.683 GBSB[2168:15b03] These are the times avail: (
    "2012-08-31 08:00:00 America/Los_Angeles",
    "2012-08-31 08:15:00 America/Los_Angeles"
)
2012-08-31 11:35:39.683 GBSB[2168:15b03] These are the times avail: (
    "2012-08-31 08:00:00 America/Los_Angeles",
    "2012-08-31 08:15:00 America/Los_Angeles",
    "2012-08-31 08:30:00 America/Los_Angeles"
)
2012-08-31 11:35:39.684 GBSB[2168:15b03] These are the times avail: (
    "2012-08-31 08:00:00 America/Los_Angeles",
    "2012-08-31 08:15:00 America/Los_Angeles",
    "2012-08-31 08:30:00 America/Los_Angeles",
    "2012-08-31 08:45:00 America/Los_Angeles"
)
2012-08-31 11:35:39.684 GBSB[2168:15b03] These are the times avail: (
    "2012-08-31 08:00:00 America/Los_Angeles",
    "2012-08-31 08:15:00 America/Los_Angeles",
    "2012-08-31 08:30:00 America/Los_Angeles",
    "2012-08-31 08:45:00 America/Los_Angeles",
    "2012-08-31 09:00:00 America/Los_Angeles"
)
2012-08-31 11:35:39.684 GBSB[2168:15b03] These are the times avail: (
    "2012-08-31 08:00:00 America/Los_Angeles",
    "2012-08-31 08:15:00 America/Los_Angeles",
    "2012-08-31 08:30:00 America/Los_Angeles",
    "2012-08-31 08:45:00 America/Los_Angeles",
    "2012-08-31 09:00:00 America/Los_Angeles",
    "2012-08-31 09:15:00 America/Los_Angeles"
)

这是我正在使用的代码。

- (void)fetchedData:(NSData *)responseData {
    //parse out the json data

    NSError* error;

    NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];


    NSDictionary* myslots =[json objectForKey:@"slots"];
    for (NSString *slotKey in myslots.allKeys) {
    NSDictionary *slot = [myslots valueForKey:slotKey];
        NSArray *tests = [myslots objectForKey:slotKey];
        NSMutableArray *timesArray = [[NSMutableArray alloc] init];
    for (NSDictionary *myDays in tests){

        if ([[myDays objectForKey:@"isReservable"] isEqualToNumber:[NSNumber numberWithInt:1]])
          [timesArray addObject:[myDays objectForKey:@"begin"]];

       NSLog(@"These are the times avail: %@", timesArray);

    }
    }
4

1 回答 1

0

看起来你忘记了你的if陈述的括号:

for (NSDictionary *myDays in tests){
    if ([[myDays objectForKey:@"isReservable"] isEqualToNumber:[NSNumber numberWithInt:1]]) {
        [timesArray addObject:[myDays objectForKey:@"begin"]];
        NSLog(@"These are the times avail: %@", timesArray);
    }
}

这能解决吗?测试一下,让我知道。

于 2012-08-31T19:01:00.170 回答