如何从Objective C中的另一个值替换NSDictionary值?

时间:2015-11-05 13:29:49

标签: ios nsmutablearray nsdictionary

我的下面有div

div

我想要做的是,替换“bid_currencycode”= 4;由不同的值。我想用5替换4.我怎么能这样做?请有人帮助我。

谢谢

2 个答案:

答案 0 :(得分:3)

您可以使用以下代码执行相同的操作:

def find_last(s):
    temp = list(enumerate(s))
    temp.reverse()
    for pos, chr in temp:
        try:
            return(pos, int(chr))
        except ValueError:
            continue

下面:

  • // Getting the dictionary from your array and making it to a mutable copy NSMutableDictionary *dict = [yourArray[index] mutableCopy]; // Changing the specified key [dict setObject:@(5) forKey:@"bid_currencycode"]; // Replacing the current dictionary with modified one [yourArray replaceObjectAtIndex:index withObject:dict]; yourArray
  • NSMutableArray是一个有效的索引(对象的索引,您需要更改该值)

答案 1 :(得分:1)

参考以下编码

NSMutableDictionary *dict =[[NSMutableDictionary alloc]init];

//your array

dic =[yourArray objectAtIndex:0];

[dict removeObjectForKey:@"bid_currencycode"];

[dict setObject:@“5” forKey:@"bid_currencycode"];

[yourArray replaceObjectAtIndex:0 withObject:dict];

0是(yourArray索引号)您可以根据数组索引号

进行更改
相关问题