2012-10-24 50 views
1

我在iphone新development.recently我开始project.after JSON解析我有一个如何使用新密钥将数据添加到nsmutable数组中?

NSmutablearray 
(
    { 
    "contest_description" = " "; 
    "contest_id" = 245; 
    "contest_name" = "teating1 "; 
    "contest_status" = Running; 
    "creator_id" = "1716091396 "; 
    "end_time" = "2012-10-26 04:10:25"; 
    "full_name" = "Adit Hasan "; 
    "no_of_contestants" = 3; 
    "no_of_days" = 5; 
    "start_time" = "2012-10-21 04:10:24"; 
    "time_stamp" = "2012-10-24 04:11:09"; 
    "winner_user_id" = "Not Yet"; 
    }, 
    { 
    "contest_description" = " "; 
    "contest_id" = 248; 
    "contest_name" = "hhhhhhk "; 
    "contest_status" = Running; 
    "creator_id" = "1716091396 "; 
    "end_time" = "2012-10-25 13:33:35"; 
    "full_name" = "Adit Hasan "; 
    "no_of_contestants" = 2; 
    "no_of_days" = 4; 
    "start_time" = "2012-10-21 13:33:34"; 
    "time_stamp" = "2012-10-23 13:35:09"; 
    "winner_user_id" = "Not Yet"; 
    }, 
) 

如何添加新的密钥像updated_image和值分配给此项?

回答

0

基本上你有什么是NSDictionaryNSArray,我不知道这是否是Mutable这就是为什么我指的是他们作为正常NS不变类,如果他们是不可变的,你需要将它们转换为Mutable对象。像如下

NSMutableArray *mutableArray = [NSMutableArray arrayWithArray:yourPreviousArray];

NSMutableDictionary *mutableDictionary = [NSMutableDictionary dictionaryWithDictionary:previousDictionary];

任何怎么样,这是我觉得你的问题的解决方案是,正在考虑将现有的阵列(并不重要,如果它不是,只要你没有添加新的字典)和字典是可变的。

for (NSMutableDictionary *dictionary in previousArray) { 
    [dictionary setValue:updated_image forKey:@"updated_image"]; 
} 

如果要设置新键updated_image后的值,初始化它作为NULL,后来设置。

你为什么不给下面

NSArray Class Reference

NSMutableArray Class Reference

NSDictionary Class Reference

NSMutableDictionary Class Reference

而且还示例程序有一个良好的阅读。

相关问题