gpt4 book ai didi

ios - 读出 Plist 问题

转载 作者:行者123 更新时间:2023-11-28 20:40:29 26 4
gpt4 key购买 nike

为什么 naam 输出(NULL)? (抱歉,我知道这是基本的东西,但我是 plist 的新手)

这是plist: enter image description here

方法如下:

- (id) init {

self = [super init];
if (self) {
NSString *errorDesc = nil;
NSPropertyListFormat format;
NSString *plistPath;
NSString *rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES) objectAtIndex:0];
plistPath = [rootPath stringByAppendingPathComponent:@"Data.plist"];
NSLog(@"path: %@",plistPath);
if (![[NSFileManager defaultManager] fileExistsAtPath:plistPath]) {
plistPath = [[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"];
}
NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath];

NSDictionary *temp = (NSDictionary *)[NSPropertyListSerialization
propertyListFromData:plistXML
mutabilityOption:NSPropertyListMutableContainersAndLeaves
format:&format
errorDescription:&errorDesc];
NSLog(@"temp: %@",temp);
if (!temp) {
NSLog(@"Error reading plist: %@, format: %d", errorDesc, format);
}
self.personName = [temp objectForKey:@"Name"];
NSLog(@"NAAM:%@",[temp objectForKey:@"Name"]);
self.phoneNumbers = [NSMutableArray arrayWithArray:[temp objectForKey:@"Phones"]];


}
return self;}

the output

最佳答案

因为 temp 是一个字典,只包含一个键:@"Root"。您正在内部字典中寻找一个对象:[[temp objectForKey:@"Root"] objectForKey:@"Name"]

关于ios - 读出 Plist 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8741181/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com