Why does string show up in NSDictionary with quotes, but others don't? [duplicate]

霸气de小男生 提交于 2019-11-28 01:07:34

问题


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"]);

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...

Log:

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)

回答1:


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.



来源:https://stackoverflow.com/questions/10520486/why-does-string-show-up-in-nsdictionary-with-quotes-but-others-dont

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!