为什么字符串在NSDictionary中显示引号,但其他字母不显示? [英] Why does string show up in NSDictionary with quotes, but others don't?

查看:257
本文介绍了为什么字符串在NSDictionary中显示引号,但其他字母不显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我填充了一个NSMutableDictionary,但是当我将内容输出到NSLog时,在for循环中输入的条目的键和值显示不同,并且最终的NSLog调用甚至不输出任何内容。这里发生了什么???请帮忙!为什么在for循环中添加条目周围的引号???

So I have an NSMutableDictionary that I populate, but when I output the contents to NSLog, the key and value for the entries entered in the for loop show up differently, and the final NSLog call doesn't even output anything. What's going on here??? Please help! Why are the quotes around the entries added in the for loop???

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???这里发生的任何事情都阻止我访问该词典条目......

Output of NSLog (I only added one value in the for loop: "SourceName_0" = "tbyg.jpg", but why the quotes around "SourceName_0"??? Whatever is happening here is preventing me from accessing that dictionary entry...

日志:

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)


推荐答案

出现引号是因为字符串包含除了基本字母数字之外的东西 - 在本例中是下划线。这与tbyg.jpg和<$的原因相同c $ c>6bcb4126-4bbe-4b3d-be45-9a06cf56a22f有引号(分别包含点和短划线)。这就是描述方法有效。它不会导致你的秒ond log to fail。

The quotes appear because the string contains something besides basic alphanumerics — in this case, an underscore. It's the same reason "tbyg.jpg" and "6bcb4126-4bbe-4b3d-be45-9a06cf56a22f" have quotes (they contain a dot and dashes, respectively). That's just how the description method works. It wouldn't cause your second log to fail.

这篇关于为什么字符串在NSDictionary中显示引号,但其他字母不显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆