-1
我將一個nsmutabledictionary中的項添加到另一個nsmutabledictionary,但字典已將它作爲字符串值添加,而不是字典。這裏是我的代碼:將NSMutableDictionary添加到NSMutableDictionary將字典添加爲字符串
// mainDictionary contains dictionaries
NSMutableDictionary *result=[[NSMutableDictionary alloc]init];
for (id key in mainDictionary) {
[result addEntriesFromDictionary:[mainDictionary objectForKey:key]];
NSLog(@"type of class %@", NSStringFromClass([[result valueForKeyPath:@"key"] class]));
}
的NSLog的輸出如下:
type of class __NSCFString
我的問題是如何能在詞典添加到新的字典保持字典的完整性?
我會很感激你幫
我對這裏的數據結構有點困惑,這個'mainDictionary'應該是一個包含字典的字典嗎? – Chuck
mainDictionary包含字典 – HelenaM
只需嘗試'[result addEntriesFromDictionary:mainDictionary];'(以防萬一'mainDictionary'是你想要添加到另一個字典中的所需字典 – danypata