gpt4 book ai didi

objective-c - objectForKey 不返回任何内容

转载 作者:行者123 更新时间:2023-11-29 04:58:49 25 4
gpt4 key购买 nike

-(NSMutableDictionary *)request:(NSString *)requestString {
NSString *filepath = [[NSBundle mainBundle] pathForResource:requestString ofType:@"xml"];
NSError *error = nil;
respString = [NSString stringWithContentsOfFile:filepath usedEncoding:nil error:&error];
NSLog(@"Ping xml");
tempDict = [[NSMutableDictionary alloc] initWithDictionary:[parser readXMLString:respString]];
NSLog(@"%@",tempDict);
return tempDict;
}

直到那里,一切都正常,NSLog 显示 tempDict 中有 2 个对象和键。但随后:

-(int) authenticateUser {
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] initWithDictionary:[self request:@"login"]];
if ([[dictionary objectForKey:@"sessionId0"] isEqualToString:@"-1"] ) {
//Some code
}
else {
cError = 1;
NSLog(@"%@",[dictionary objectForKey:@"sessionId0"]);
appDelegate.sessionId = [dictionary objectForKey:@"sessionId0"];
}
[dictionary release];
return cError;
}

在最后一个 else 中,cError 为 1,NSLog 对该对象输出 nil。(整个字典的 NSLog 也输出 nil)

最佳答案

将此代码放入您的代码中,看看 dict 对象的输出是什么...

-(int) authenticateUser {
NSDictionary* dict = (NSDictionary *)[self request:@"login"];
NSLog(@"Dictionary %@",dict);

NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] initWithDictionary:[self request:@"login"]];
if ([[dictionary objectForKey:@"sessionId0"] isEqualToString:@"-1"] ) {
//Some code
}
else {
cError = 1;
NSLog(@"%@",[dictionary objectForKey:@"sessionId"]);
appDelegate.sessionId = [dictionary objectForKey:@"sessionId"];
}
[dictionary release];
return cError;
}

关于objective-c - objectForKey 不返回任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7409576/

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