1

我使用以下代码将 plist 显示到 NSDictionary/NSMutableDictionary 中,但是当我打印该变量时它返回空值?请帮我?

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *Path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Recent.plist"];
NSLog(@"%@",Path); //Path is correct

NSDictionary *d=[[NSDictionary alloc]initWithContentsOfFile:Path];
NSMutableDictionary *data = [[NSMutableDictionary alloc]initWithContentsOfFile:Path];
NSLog(@"%@",d);
4

1 回答 1

0

伙计,您的代码是正确的,但请确保您的 plist 根是数组或字典

我认为在你的情况下它应该是数组

请尝试此代码,我只是在您的代码中将 NSMutableDictionary 更改为 NSMutableArray

  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *Path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Recent.plist"];
NSLog(@"%@",Path);


NSMutableArray *d = [[NSMutableArray alloc]initWithContentsOfFile:Path];

它必须工作

于 2013-05-18T06:51:17.753 回答