2015-11-05 70 views
0

我有一個NSMutableArray下面這樣如何從目標C中的另一個值替換NSDictionary值?

(
    { 
    Realimg = "<UIImage: 0x13951b130>, {800, 600}"; 
    "bid_accepted" = 1; 
    "bid_amount" = 100; 
    "bid_amount_num" = 100; 
    "bid_cur_name" = USD; 
    "bid_cur_symb" = $; 
    "bid_currencycode" = 4; 
    "bid_date" = "05 Nov 2015"; 
    "bid_msg" = testing; 
    "bid_user_id" = 2; 
    "nego_id" = 612; 
    "pas_count" = 5; 
    "ride_address" = "Sample Address"; 
    "ride_cover_img" = "uploadfiles/UploadUserImages/2/mobile/21426739600s-end-horton-plains.jpg"; 
    "ride_id" = 149; 
    "ride_name" = "Ride to the World's End"; 
    "ride_type_id" = 0; 
    "ride_type_name" = Travel; 
    "ride_user_fname" = Nik; 
    "ride_user_id" = 2; 
    "ride_user_lname" = Mike; 
    } 

) 

我想要做的是,取代 「bid_currencycode」= 4;由一個不同的值。我想用5替換4。我怎麼能做到這一點?請有人幫助我。

謝謝

+1

你可以發佈你正在使用創建數組或做更改代碼更換 –

回答

3

您可以使用下面的代碼做同樣的:

// 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]; 

這裏:

  • yourArrayNSMutableArray
  • index是有效的索引(索引的對象,你需要改變它的值)
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索引號),您可以根據您的數組索引號