2012-04-28 49 views

回答

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

1 NumberX =值)獲取的數據(即NSMutableDictionary *)從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]; 
+0

生病稍後再試此,感謝您的快速答覆。 – akuritsu 2012-04-28 05:43:09