Web 服务调用返回 JSON 响应,我将其放入 NSMutableArray。JSON 响应如下所示,
(
{
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;
}
)
现在我想创建另一个NSMutableDictionary
只包含键DispName和Int_Adr。
所以我正在做这样的事情。我已经NSMutableDictionary
像这样在 .h 文件中声明了 a 。
@property (nonatomic, strong) NSMutableDictionary *recipients;
在 .m 文件中,
// 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!
我只将这两个值设置为收件人字典。但是当我记录输出时,它只显示最后一组。
{
DispName = "Rahul Dravid (Indian Premier League)";
"Int_Adr" = 266;
}
我怎么解决这个问题?
谢谢你。