【问题标题】:Why don't count the elements of array? [duplicate]为什么不计算数组的元素? [复制]
【发布时间】:2012-04-05 06:31:47
【问题描述】:

文件中有 9 个字典,每个字典有两个键。我想获得一个字典数组。我得到数组元素是:0 这是代码:

NSString * path = [[NSBundle mainBundle]pathForResource:@"List" ofType: @"plist"];

 NSArray *array = [NSArray arrayWithContentsOfFile:path];  

提前致谢

【问题讨论】:

  • 请确认您的路径有效(不是 nil)并在 xcode 中显示您的 plist 的内容。
  • PL.检查该链接并评论您的问题是否已解决。

标签: iphone ios


【解决方案1】:
NSString *file = [[NSBundle mainBundle] pathForResource:@"List" ofType:@"plist"];
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:file];
NSArray *array = [dict objectForKey:@"Array"];

希望对你有帮助

您的 plist 是字典而不是数组。所以看看这个。

【讨论】:

  • 谢谢,我错了plist的根。我写的是 而不是 。非常感谢
  • 是的。这只是一个例子。如果对您有帮助,请接受。
猜你喜欢
  • 1970-01-01
  • 2017-09-11
  • 1970-01-01
  • 2023-04-01
  • 1970-01-01
  • 2016-12-20
  • 1970-01-01
  • 2014-09-30
相关资源
最近更新 更多