[英]How to read and parse a plist
I like to read and parse plist files, but It wont work. 我喜欢阅读和解析plist文件,但无法正常工作。
This is my code: NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:self.plistPath];
这是我的代码:
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:self.plistPath];
dict always is (null) dict总是(null)
I tryed to get the content as string, here is my code: 我试图以字符串形式获取内容,这是我的代码:
NSString *string = [[NSString alloc] initWithData:[NSData dataWithContentsOfFile:self.plistPath] encoding:NSUTF8StringEncoding];
self.plistPath is /tmp/com.apple.audio.hogmode.plist
And this is the content of the plist: 这是plist的内容:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
</plist>
What am I doing wrong? 我究竟做错了什么?
Figured it out! 弄清楚了!
NSString *error;
NSPropertyListFormat format;
NSDictionary *dict = [NSPropertyListSerialization propertyListFromData:[NSData dataWithContentsOfFile:self.plistPath] mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&error];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.