Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在收集未知结构的 JSON 数据,并尝试在allKeys. 但是当我到达底部并allKeys应用于不是字典的东西时,当然会引发错误并且代码崩溃。如何检测错误并避免崩溃?
allKeys
检查您正在使用的对象确实是一个 NSDictionary:
for (id obj in array) { if ([obj isKindOfClass:[NSDictionary class]]) { for( NSString *aKey in [(NSDictionary *)obj allKeys] ) { NSLog(@"Key: %@", aKey); } } }