如何将nsmutabledictionary中nsmutablearray的值赋值给另一个nsmutable字典

时间:2014-07-04 06:36:35

标签: ios nsmutablearray nsmutabledictionary

如何将nsmutable字典中的nsmutable数组的值分配给另一个nsmutable字典或NSDictionary?

  NSMutableDictionary *readers = [[NSMutableDictionary alloc] init];
[readers setObject:[[NSMutableArray alloc] init] forKey:@"id"];
readers[@"publicAccess"] = @NO;



// Create dictionary of parameters to be passed with the request
NSDictionary *data = @{
     // @"reader_ids": [NSString  stringWithFormat:@"%@",[readers[@"id"]componentsJoinedByString:@","]],

                       };

 NSDictionary *data = @{
     @"reader_ids": // i need here values of "id" as string which is separated by comma since  **reader_ids** is string property and id is MSMutable Array which contains datas.

我需要获得 id publicAccess 的价值并分配到另一个NSDictionary。

1 个答案:

答案 0 :(得分:0)

试试这个

 NSMutableArray *mArray = readers[@"id"];
    BOOL publicAccess = readers[@"publicAccess"];
NSNumber *num = [NSNumber numberWithBool: publicAccess];

NSString * result = [mArray componentsJoinedByString:@","]
     NSDictionary * data = @{@"readers_ids" :result,@"publicAccess" : num};