我有一本输入字典,如下所示:
(已更新)
{
"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];
}
}
}
最佳答案
这三个值位于名为“ StationFavourites.plist”的键下。
因此,尝试类似:
[(NSDictionary *)dictionary[@"StationFavourites.plist"] allValues];
关于ios - 我如何获得此NSDictionary的值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31480957/