ios 判断字典中是否有某个key

2025-05-01 07:11:56
推荐回答(2个)
回答1:

【千夏软件】认为可以这么判断:-(id)handleNullObjectForKey:(NSString *)key {
id object = [self objectForKey:key];
if ([object isKindOfClass:[NSNull class]]) {
return nil;
}
return object;
}
或者是 if ([[dic allKeys] containsObject:key])

回答2:

if ([[dic allKeys] containsObject:key]) {
str = dic[key];
}