【问题标题】:writing NSDictionary into plist将 NSDictionary 写入 plist
【发布时间】:2012-05-31 14:00:14
【问题描述】:

您好,我正在尝试将 NSDictionary 写入文档文件夹中的 plist,但无法写入,我正在使用 writeToFile:atomically: 方法,该方法返回 False。完整的代码是

-(void)writeData:(NSDictionary *)dicResponseData
{
    // get paths from root directory

    NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
    // get documents path
    NSString *documentsPath = [paths objectAtIndex:0];
    // get the path to our Data/plist file
    NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"Contractors.plist"];   

    [dicResponseData writeToFile:plistPath atomically: TRUE];  
}

该词典包含 25 个子词典。

【问题讨论】:

  • 你不接受答案,所以不太可能有人愿意帮助你。
  • @skram 现在我会接受答案,直到现在我还不知道这个过程。
  • 它发生了——你不是唯一一个。我相信从现在开始你会得到更好的回应。 :)
  • 尝试使用[dicResponseData writeToFile:plistPath options:NSDataWritingAtomic error:&error] 编写并查看错误消息。
  • @Alexander 你指定的方法我用来写 NSData ,但我需要写 NSDictionary

标签: ios plist nsdictionary writetofile


【解决方案1】:

字典中的所有对象都必须是属性列表对象。

此方法递归地验证所有包含的对象是 属性列表对象(NSData、NSDate、NSNumber 的实例, NSString、NSArray 或 NSDictionary)在写出文件之前,以及 如果所有对象都不是属性列表对象,则返回 NO,因为 结果文件不是有效的属性列表。

【讨论】:

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