2012-01-11 40 views
0

我想設置用戶名作爲重點對於此代碼:設定值

{ 
"CustomerAccount":{ 
"UserName":"String content" 
}; 

我想在這裏設置用戶名,沒有人知道我怎麼可以設置名稱與級別的字典?

我的代碼:

[mutabledictionary setObject:self.uitextfield.text forKey:UserName]; 

但是這臺下面的用戶名CustomerAccount沒有內幕CustomerAccount。

任何幫助在這裏將不勝感激。

謝謝。

回答

2

你可以只添加子字典,像這樣:

NSDictionary *userAccount = [NSDictionary dictionaryWithObject:@"String Content" forKey:@"UserName"]; 
NSMutableArray *accounts = [NSMutableArray arrayWithObject:userAccount]; 

// do something with accounts 
NSLog(@"%@", accounts); 
0

只需創建創建CustomerAccount的陣列和NSDictionary的使用。使用

[NSDictionary dictionaryWithObjects:objects forKeys:keys]; 
3

如果這兩個級別可變的字典已經存在(它不是從你的問題清楚),你需要把你的的setObject:forKey消息發送到第二級字典,像這樣:

[[mutabledictionary objectForKey:@"CustomerAccount"] setObject:self.uitextfield.text forKey:UserName]; 
+0

這正是我正在尋找..謝謝 – kforkarim 2012-01-12 18:09:37

+0

由於未捕獲異常'NSInternalInconsistencyException',原因:' - [__ NSCFDictionary setObject:forKey:]:發送到不可變對象的變異方法 – Alex 2014-01-20 11:42:27