0

I am getting my data but it seems like the data is posting in NSLog everytime it finds my "is reservable"=1; I think this should only post once and when I display it in a tableview cell would it post more than once? Here is my 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"
)

Here is my code I am using.

- (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);

    }
    }
TIDev
  • 109
  • 4
  • 10
  • This is our fourth question today, all seemingly about the exact same problem. And its your eighth incomprehensible question about JSON. – woz Aug 31 '12 at 18:45
  • I have been making progress on each question. The other questions were accepted already. – TIDev Aug 31 '12 at 18:46
  • That's fine, but asking question after question about the same project implies that you are not doing enough to find the answers on your own. – woz Aug 31 '12 at 18:48
  • Should I have just replace existing question each time I get a little further? Sorry about that. – TIDev Aug 31 '12 at 18:49
  • No, I wouldn't do that either. Just try to work through the answer yourself as much as you can before posting. – woz Aug 31 '12 at 18:51
  • It looks like you have the `NSLog` inside your loop. Wouldn't you expect it to be called repeatedly? – woz Aug 31 '12 at 18:52
  • I have been but I am still learning. Thank you for all the advice. – TIDev Aug 31 '12 at 18:52
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/16109/discussion-between-woz-and-tidev) – woz Aug 31 '12 at 18:53

1 Answers1

0

It looks like you are forgetting your brackets for your if statement:

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);
    }
}

Does that fix it? Test it out and let me know.

woz
  • 10,888
  • 3
  • 34
  • 64
  • I had to move the NSLog out of first bracket. Another issue now but one solved. Thanks! – TIDev Aug 31 '12 at 19:17