如何判断NSMutableDictionary是否有某个key

if ([[dict allKeys] containsObject:key) {
// contains key
}

if ([dict objectForKey:key]) {  //objectForKey will return nil if a key doesn't exists.

// contains key
}

猜你喜欢

转载自blog.csdn.net/quantum7/article/details/80676697