如何获得这个NSDictionary的值



我有一个传入的字典,看起来如下:(这是更新)

{
"StationFavorites.plist" =     {
    "Addison Road" =         {
        Code = G03;
        Lat = "38.8867478168";
        Line = BL;
        Lon = "-76.89410791";
        Name = "Addison Road";
        Type = 1;
    };
    Anacostia =         {
        Code = F06;
        Lat = "38.8629631168";
        Line = GR;
        Lon = "-76.9953707387";
        Name = Anacostia;
        Type = 1;
    };
    Archives =         {
        Code = F02;
        Lat = "38.8936652235";
        Line = GR;
        Lon = "-77.0219143879";
        Name = Archives;
        Type = 1;
    };
};

}

我已尝试将其转换为数组:

NSArray *array = [dictionary allValues];

但是我最终在数组中得到了一个元素,而我想要三个。我该怎么做呢?

更新:按要求,这是我当前的代码片段。

- (void)awakeWithContext:(id)context {
    [super awakeWithContext:context];
    if ([WCSession isSupported]) {
        NSLog(@"session isSupported...");
        self.session = [WCSession defaultSession];
        self.session.delegate = self;
        [self.session activateSession];
        NSError *error = nil;
        NSArray *directories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documents = [directories firstObject];
        pathString = [documents stringByAppendingPathComponent:@"Favorites.plist"];
        NSLog(@"pathString > %@", pathString);
        NSFileManager *fileManager = [NSFileManager defaultManager];
        if (![fileManager fileExistsAtPath: pathString]) //4
        {
            NSString *bundle = [[NSBundle mainBundle] pathForResource:@"Favorites" ofType:@"plist"];
            [fileManager copyItemAtPath:bundle toPath: pathString error:&error];
        }
        if ([[NSFileManager defaultManager] fileExistsAtPath:pathString]) {
            [self readFromFile:pathString];
            NSMutableDictionary  *dictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:pathString];
            //NSLog(@" count: %lu", (unsigned long)dictionary.count);
            NSLog(@" dictionary: %@", dictionary);
            NSArray *tempArray = [dictionary allValues];
            self.workingArray = [tempArray mutableCopy];
            [self configureTable];
        }
    }
}

这三个值位于一个名为" stationfavorites .plist"的键下

所以试试这样写:

[(NSDictionary *)dictionary[@"StationFavourites.plist"] allValues];
 for (NSString *key in [dictionary allKeys]) {
        NSDictionary *currDict = dictionary[key];
       // you can create here from the valueDict a new Object and store it for example in an Array
 }

最新更新