从plist创建字典并返回null

Blu*_*eni -1 objective-c ios

我的项目中有一个plist文件,如下所示: plist中

而我正在这样做

NSURL *file = [[NSBundle mainBundle] URLForResource:@"test" withExtension:@"plist"]; //Lets get the file location

    NSDictionary *plistContent = [NSDictionary dictionaryWithContentsOfURL:file];
    NSLog(@"dic::%@", plistContent);

     NSArray *arrayRead  = [plistContent allKeys];
    NSLog(@"test::%@", arrayRead);
Run Code Online (Sandbox Code Playgroud)

我似乎做的所有事情都在我的日志中返回(null).有什么想法吗?

rma*_*ddy 6

你的plist root是一个数组,而不是字典.使用:

NSArray *plistContent = [NSArray arrayWithContentsOfURL:file];
Run Code Online (Sandbox Code Playgroud)

当然,你现在有一系列字典.你不能简单地要求allKeys了.