0

我有字典内容数组,但我无法获取字典值。下面是字典格式,字典中的“resdata”和时间戳是字典键值。所以我需要知道如何获取时间戳值。

 <__NSArrayM 0x89426d0>(
{
    resData =     (
                {

                timestamp = "2012-04-09 13:54:08 +0000";

               }
    );
    seqCounter = 101;
}


here is the source code
 for (int i = 0; i < [self.gluClkDetailArray count]; i++) 
        {
            NSMutableDictionary *mDict = [self.gluClkDetailArray objectAtIndex:i];
            NSDate *mDate = [[mDict objectForKey:@"resData"] objectForKey:@"timestamp"];
            NSLog(@"NSDATE-----%@", mDate);
        }

In above code the dictionary value is 0.

Thanks in advance
4

1 回答 1

1

resData is an array of dictionaries.

Index into the array:

for (NSDictionary *mDict in self.gluClkDetailArray) {
    NSArray *resData = [mDict objectForKey:@"resData"];
    NSString *timestamp = [[resData objectAtIndex:0] objectForKey:@"timestamp"];
    NSLog(@"timestamp: %@", timestamp);
}

Example (with llvm 4.0):

NSArray *a = @[ @{ @"resData"    : @[ @{ @"timestamp" : @"2012-04-09 13:54:08 +0000" } ],
                   @"seqCounter" : @101
                 }
             ];
NSLog(@"a: %@", a);

for (NSDictionary *mDict in a) {
    NSArray *resData = [mDict objectForKey:@"resData"];
    NSString *timestamp = [[resData objectAtIndex:0] objectForKey:@"timestamp"];
    NSLog(@"timestamp: %@", timestamp);
}

NSLog output:

a: (
        {
        resData =         (
                        {
                timestamp = "2012-04-09 13:54:08 +0000";
            }
        );
        seqCounter = 101;
    }
)

timestamp: 2012-04-09 13:54:08 +0000

于 2012-04-09T14:59:26.650 回答