我的代码如下:虽然它有数据,但无法从NSMutableDictionary中检索密钥的值
1.我有一个按钮的操作方法如下。
(IBAction)enableDisableFB:(id)sender {//have below local variable
NSMutableDictionary *fbLocationLatitude = [[NSMutableDictionary alloc] init];
2.有一个循环,我在这个字典中设置对象,如
[fbLocationLatitude setObject:latitude forKey:locID]; //here latitude and locID both are NSString
3.In在同一方法的另一种循环,我试图找回价值,但它给了(空)在NSLog的
NSLog(@"latitude for key %@ = %@",locID, [fbLocationLatitude objectForKey:locID]);
//above statement gives me output -> latitude for key 114943251851302 = (null)
但环之后我打印使用
NSLog(@"location dictionary = %@",fbLocationLatitude);
//which gives me below output. Sample given
location dictionary = {
114943251851302 = "40.4414";
109782595706984 = "38.9966";
108867759137051 = "22.47";
110148382341970 = "25.7877";
107611279261754 = "43.1655";
111803735513513 = "27.1828";
109155699106505 = "18.3167";
103734539665100 = "19.09";
完整词典
这有我正在寻找的键值,但同样我无法使用objectForKey。 请帮我解决这个问题。
for (NSUInteger i =0; i< [fbLocationID count];i++)
{
// NSLog(@"person creation");
NSString *locID = [NSString stringWithString:[fbLocationID objectAtIndex:i]];
NSLog(@"latitude for key %@ = %@",locID, [fbLocationLatitude objectForKey:locID]);
}
NSLog(@"location dictionary = %@",fbLocationLatitude);
这是代码是如何。我也尝试使用下面的代码
for (id ik in [fbLocationLatitude allKeys])
{
const char* classname=class_getName([ik class]);
NSLog(@"class of key %s",classname);
}
打印类键和我得到ANS为:类键NSDecimalNumber 虽然类型转换的LOCID到NSDecimalNumber,我没有得到的关键,但只有空精确值。 请帮忙解决这个问题。
当你向字典中添加值时,你是否正面'latitude'不是'nil'? –
在哪个循环之后,字典的日志会为您提供正确的值?第一个添加值的位置,或第二个您尝试检索它们的位置? – rdelmar
在你的NSLog调用之前设置一个断点并检查gdb中字典内容的类型和值。 – Samir