6

我有一个名为 NumberX 的整数和一个名为 PlistX 的 plist。

例子

int NumberX;

PlistX:

列表

我想知道如何使 NumberX = 值为三

4

2 回答 2

15

试试这个:

NSString *path = [[NSBundle mainBundle] pathForResource:@"PlistX" ofType:@"plist"];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
int number = [[[[dict objectForKey:@"One"] objectForKey:@"Two"]objectForKey:@"Three"] intValue];
NSLog(@"%d",number);    
于 2012-04-28T09:36:19.480 回答
3

NSMutableDictionary *1)从保存到磁盘的plist获取数据(即):

NSMutableDictionary *dictionary =  [NSPropertyListSerialization propertyListFromData:data mutabilityOption:NSPropertyListMutableContainers format:NULL errorDescription:&error];

2) 从字典中检索需要的对象。

//in your case
NSNumber *tmpNumber = [[[dictionary objectForKey:@"One"] objectForKey:@"Two"] objectForKey:@"Three"];
// convert to int
int NumberX = [tmpNumber intValue];
于 2012-04-28T05:26:48.287 回答