所以我填充了一个NSMutableDictionary,但是当我将内容输出到NSLog时,在for循环中输入的条目的键和值显示不同,并且最终的NSLog调用甚至不输出任何内容。这里发生了什么???请帮忙!为什么在for循环中添加了条目周围的引号???
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
numberOfPhotosAsString, @"PackageFileCount",
wtID, @"wtID",
uploadType, @"type",
nil];
for (int i= 0; i < photos.count; i++)
{
NSString *finalFileName = [fileNameBase stringByAppendingFormat:@"%i", i];
[params setObject:[[fileNames objectAtIndex:i] stringByAppendingString:@".jpg"] forKey:finalFileName];
// This one doesn't do anything differently:
//[params setValue:[[fileNames objectAtIndex:i] stringByAppendingString:@".jpg"] forKey:[fileNameBase stringByAppendingFormat:@"%i", i]];
}
NSLog(@"Params: %@", params);
NSLog(@"Value: %@", [params objectForKey:@"SourceName_0"]);
NSLog的输出(我只在for循环中添加了一个值:“SourceName_0”=“tbyg.jpg”,但为什么引用“SourceName_0”?这里发生的任何事情都阻止我访问该词典条目...
日志:
2012-05-09 12:38:26.448 PhotoUp[6231:707] Params: {
PackageFileCount = 1;
"SourceName_0" = "tbyg.jpg";
type = T;
wtID = "6bcb4126-4bbe-4b3d-be45-9a06cf56a22f";
}
2012-05-09 12:38:26.449 PhotoUp[6231:707] Value: (null)
答案 0 :(得分:13)
出现引号是因为字符串包含除基本字母数字之外的内容 - 在本例中为下划线。这与"tbyg.jpg"
和"6bcb4126-4bbe-4b3d-be45-9a06cf56a22f"
引用的原因相同(它们分别包含点和短划线)。这就是description
方法的工作原理。它不会导致您的第二个日志失败。