ios - 如何从数组内的字典中的 'key' 获取 'value'?

标签 ios objective-c arrays key nsdictionary

这是字典,在数组中,

array With Dict : (
        {
        id = 1;
        name = Arjun;
    },
        {
        id = 2;
        name = Karan;
    },
        {
        id = 3;
        name = Ajit;
    },
        {
        id = 4;
        name = Prashant;
    },
        {
        id = 5;
        name = Sushant;
    }
)

当我选择任何“值”时,我想获取与该值关联的“键”。

例如:

假设我选择了“Prashant”并且我想要它的“id”,即 4。

如何从“值”中获取“键”?

最佳答案

NSString *myName = @"Prashant";
for (NSDictionary *dict in array) {
    if ([dict[@"name"] isEqualToString:myName]) {
        NSLog(@"%@", dict[@"id"]);
        break;
    }
}

关于ios - 如何从数组内的字典中的 'key' 获取 'value'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48720191/

相关文章:

ios - 如何在 ios 中绘制折线图?任何可以帮助我在 ios 中显示图形数据的控件

objective-c - 在 iPhone 上使用 UINavigationController 的 setViewController 行为不正常

javascript - 使用数组属性展平复杂对象的数组

javascript - 如何正确构建多维更新对象/数组并将其修补到现有的多维对象上? (javascript)

ios - NsNumberFormatter 没有给出正确的结果

ios - NEON程序集无法在Xcode 4.3.2中为iOS构建

iphone - 仅在为模拟器构建时复制符号

C# 将 View 状态转换为 bool 数组

objective-c - 为 PDF 查看器自动调整 UIViews 的大小

ios - 在 objective-c 中使用联系人框架时无法在 TableView 中显示联系人缩略图