A web service call returns a JSON response and I'm putting it in to an NSMutableArray. The JSON response looks like this,
(
{
DispName = "Jonny Depp (Marvel Comics)";
"Int_Adr" = 273;
"Int_Group" = 0;
},
{
DispName = "Mahendra Singh Dhoni (Indian Premier League)";
"Int_Adr" = 265;
"Int_Group" = 0;
},
{
DispName = "Otara De Mel (ODEL UNLIMITED)";
"Int_Adr" = 496;
"Int_Group" = 0;
},
{
DispName = "Rahul Dravid (Indian Premier League)";
"Int_Adr" = 266;
"Int_Group" = 0;
}
)
Now I want to create another NSMutableDictionary containing only the keys, DispName and Int_Adr.
So I'm doing something like this. I have declared a NSMutableDictionary in the .h file like this.
@property (nonatomic, strong) NSMutableDictionary *recipients;
In the .m file,
// get the JSON response and put it in an array
NSMutableArray *contactsArray = [jsonParser objectWithString:response];
NSLog(@"%@, array count = %d", contactsArray, contactsArray.count); // the count is 50
//[self.recipients removeAllObjects];
for (NSDictionary *item in contactsArray) {
[self.recipients setObject:[item objectForKey:@"Int_Adr"] forKey:@"Int_Adr"];
[self.recipients setObject:[item objectForKey:@"DispName"] forKey:@"DispName"];
}
NSLog(@"%@, array count = %d", self.recipients, self.recipients.count); // the count shows 2!
I'm setting only those 2 values to the recipients dictionary. But when I log the output, it shows only the last set.
{
DispName = "Rahul Dravid (Indian Premier League)";
"Int_Adr" = 266;
}
How can I solve this problem?
Thank you.