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!
これら 2 つの値のみを受信者辞書に設定しています。しかし、出力をログに記録すると、最後のセットのみが表示されます。
{
DispName = "Rahul Dravid (Indian Premier League)";
"Int_Adr" = 266;
}
どうすればこの問題を解決できますか?
ありがとうございました。