这是我的代码

for(id tempLangItem in jp.staffData)
        {
 NSMutableDictionary *temp=[[NSMutableDictionary alloc] initWithDictionary:tempLangItem];
            NSString *name = [temp objectForKey:@"lang_name"];
            NSLog(@"item_name =%@",name);
            NSLog(@"value in dictionary=%@",temp);



}


这些是日志详细信息

item_name =marinieres

 value_in_dictionary={
    "lang_id" = 2;
    "lang_name" = "\U7a46\U840a\U65afmarinieres";
    time = "2013-06-05 05:14:50";
}


为什么在lang_name=\U7a46\U840a\U65afmarinieres日志中显示正确的同时在value_in_dictionary日志中给出item_name的原因。

最佳答案

试过了

NSMutableDictionary *temp=[[NSMutableDictionary alloc]init];
[temp setObject:@"marinieres" forKey:@"lang_name"];

NSString *name = [temp objectForKey:@"lang_name"];
NSLog(@"item_name =%@",name);
NSLog(@"value in dictionary=%@",temp);


我的日志显示了什么

2013-06-06 12:38:02.337 Cool[96423:11303] item_name =marinieres
2013-06-06 12:38:04.022 Cool[96423:11303] value in dictionary={
    "lang_name" = marinieres;
}


1个快速问题:如果是NSDictionary,为什么要创建一个新实例?

 NSMutableDictionary *temp=[[NSMutableDictionary alloc] initWithDictionary:tempLangItem];


尝试使用tempLangItem

关于ios - 赋予不当值(value)的字典,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16955655/

10-11 21:23