我在NSMutableDictionary檢索密鑰和值檢查,我做了這個代碼有點混淆。NSMutableDictionary關鍵值檢查問題
NSMutableDictionary *testDictionary=[NSMutableDictionary dictionary];
// NSMutableDictionary *testDictionary=[[NSMutableDictionary alloc]init];
[testDictionary setObject:@"Muhammed Musthafa" forKey:@"10005"];
[testDictionary setObject:@"Lubaba p" forKey:@"10006"];
[testDictionary setObject:@"Sahala Banu" forKey:@"10007"];
[testDictionary setObject:@"Vishnu k" forKey:@"10008"];
[testDictionary setObject:@"Shabeer PP" forKey:@"10009"];
[testDictionary setObject:@"Sabeehath " forKey:@"10010"];
[testDictionary setObject:@"Anusha GS" forKey:@"10011"];
[testDictionary setObject:@"JINI KS" forKey:@"10012"];
[testDictionary setObject:@"Athulya T" forKey:@"10013"];
[testDictionary setObject:@"Midhun KS" forKey:@"10014"];
for(NSString *kk in testDictionary)
{
NSString *fName;
if([email protected]"10006")
{
fName=[testDictionary objectForKey:kk];
}
if([email protected]"10007")
{
fName=[testDictionary objectForKey:kk];
}
if([email protected]"10013")
{
fName=[testDictionary objectForKey:kk];
}
NSLog(@"KEY=====%@ and Value====%@",kk,fName);
}
The out put value :
2011-11-17 10:49:37.054 ArchiveData[2539:207] KEY=====10013 and Value====
2011-11-17 10:49:37.055 ArchiveData[2539:207] KEY=====10006 and Value====
2011-11-17 10:49:37.056 ArchiveData[2539:207] KEY=====10008 and Value====
2011-11-17 10:49:37.056 ArchiveData[2539:207] KEY=====10010 and Value====
2011-11-17 10:49:37.057 ArchiveData[2539:207] KEY=====10012 and Value====
2011-11-17 10:49:37.057 ArchiveData[2539:207] KEY=====10014 and Value====
2011-11-17 10:49:37.058 ArchiveData[2539:207] KEY=====10005 and Value====
2011-11-17 10:49:37.059 ArchiveData[2539:207] KEY=====10007 and Value====
2011-11-17 10:49:37.060 ArchiveData[2539:207] KEY=====10009 and Value====
2011-11-17 10:49:37.061 ArchiveData[2539:207] KEY=====10011 and Value====
爲什麼這三{(KK == @ 「10006」)如果(KK == @ 「10007」)如果(KK == @ 「10013」)}如果狀態換貨返回false?
還有其他的方法來檢查這樣的ID鍵嗎?
我看到相同類型的編碼在一些其他編碼中工作正常,所以這取決於任何其他配置?
我該如何檢查特定鍵== @「一些鍵值」?
我無法重現您的問題。你的代碼中可能還有其他東西不在問題中顯示。 – 2011-11-17 06:50:00