0
-(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;
}
これまではすべてがOKです.NTLogは、tempDictに2つのオブジェクトとキーがあることを示しています。 しかし、その後:他に最後にobjectForKeyは何も返さない
-(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;
}
、cErrorが1である、のNSLogは、そのオブジェクトにnilを出力します。 「ログイン」@:あなたと出力は辞書オブジェクトのためであるかを確認中 (全体の辞書のためのNSLogもnilを出力)
あなたは必ず '[自己リクエストです] 'はありません? NSLogを 'authenticateUser'で試してみてください – Saphrosit
これを投げ捨てるだけですが、[self request:]で返された辞書を使うのではなく、新しい辞書を割り当てたいのですか?これはあなたの特定の質問に役立つことはありません。あなたがここでやっていることのためだけに、なぜ新しい辞書全体を割り当てて、要求の結果をコピーしたいのかわかりません。このクラスのインターフェースにrequest:メソッドを追加するのを忘れましたか? – wallacer
if文では[dictionary objectForKey:@ "sessionID0"]がチェックされますが、else部分では[dictionary objectForKey:@ "sessionID"]がチェックされます。実際のコードでは、ここに入力エラーがありますか? – sosborn