如何获取 NSMutableArray 中的键值?

How get a key value in NSMutableArray?

一个叫arrayDBNSMutableArray,它使用AFNetworking从服务器获取数据,像这样

  [self.arrayDB addObjectsFromArray:[responseObject objectForKey:@"list"]];
  NSLog(@"print:%@",self.arrayDB);

结果是这样的。

  print:(
    {
    id = 10;
    key = 7707eca6ea4d2db923c8b7b4e6ec094c;
    },
    {
    id = 9;
    key = 7aaf962bc4df61a3b44c544c58fc6c82;
    },
    {
    id = 7;
    key = ce9d9e99a96d6417c6b34321c820c4c0;
    },
    {
    id = 6;
    key = 6086663465e5813d08f862eb443e2623;
    },
    {
    id = 4;
    key = 5d9519dd7de26f0139d6028fb83a4ead;
    }
   )

而现在,我用sql语句来描述我的需求,select key from arrayDB where id=10,如何写成objective-C?

您可以这样使用 NSPredicate

NSArray *myArray = [self.arrayDB filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(id == %@)", @"10"]];