无法将 plist 加载到 NSArray 中
我正在尝试将以下 plist 加载到 NSArray 中:
这是我用来执行的代码加载数据:
// Load the data from the plist file
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"MyData" ofType:@"plist"];
NSArray *myArray = [[NSArray alloc] initWithContentsOfFile:filepath];
但是,当我在加载数据后放置断点时,我注意到数组是空的。请有人帮助我了解出了什么问题?
I'm trying to load the following plist into an NSArray:
Here is the code I'm using to load the data:
// Load the data from the plist file
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"MyData" ofType:@"plist"];
NSArray *myArray = [[NSArray alloc] initWithContentsOfFile:filepath];
However when I place a breakpoint after the data has been loaded I notice that the array is empty. Please can someone help me understand what's going wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的 plist 文件有一个包含数组的字典。试试这个
Your plist file has a dictionary that contains an array. Try this
您可以尝试将其加载到 NSDictionary 中并询问其中的
[ objectForKey:@"Root"]
吗?据我记得,属性列表是键/值映射,而您的数组只是这些值之一。
Could you try loading it into a NSDictionary and asking for the
[ objectForKey:@"Root"]
inside it ?As far as I remember, property lists are key / value maps and your array is just one of those values.