iOS NSDictionary与NSMutableDictionary差异导致的报错

报错:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__NSDictionary0 0x600000000de0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key doctorCode.'

解决:

NSDictionary *params = [[NSDictionary alloc] init];

[params setValue:doctorCode forKey:@"doctorCode"];

改为

NSMutableDictionary *params = [[NSMutableDictionary alloc] init];

[params setValue:doctorCode forKey:@"doctorCode"];

bug消失,访问数据成功!!!

应该是NSDictionary不支持为未知的key赋值,只能是它原有的key才可以。

这就是基础知识的不足导致的失误!!!

你可能感兴趣的:(iOS NSDictionary与NSMutableDictionary差异导致的报错)