【问题标题】:Read binary plist into NSDictionary将二进制 plist 读入 NSDictionary
【发布时间】:2011-07-08 08:44:50
【问题描述】:

有没有简单的方法将二进制 plist 文件解析为 NSDictionary 表示? 我正在搜索类似的东西:

NSString* strings = [NSString stringWithContentsOfURL: ... encoding: NSUnicodeStringEncoding error: ...];
NSMutableDictionary* pairs = (NSMutableDictionary*)[strings propertyListFromStringsFileFormat];

使用此代码在解析二进制 plist 文件时导致异常。

【问题讨论】:

    标签: objective-c plist


    【解决方案1】:

    你在找[NSDictionary dictionaryWithContentsOfFile:]吗?

    【讨论】:

      【解决方案2】:

      考虑到一个名为DataStorageFile.plist 的文件,您可以使用:

      NSString *dataPath = [[NSBundle mainBundle] pathForResource:@"DataStorageFile" ofType:@"plist"];
      self.data = [NSDictionary dictionaryWithContentsOfFile:dataPath];
      

      如果你想要一个数组:

      self.data = [NSArray arrayWithContentsOfFile:dataPath];
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-09-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多