【发布时间】:2023-04-07 23:29:02
【问题描述】:
我从服务器获取数据。我的应用程序在 Sinulator 和测试设备 iPhone 4s 上运行良好,但一个人在 iPod 4 上遇到问题。他得到了异常:
-[__NSCFString objectForKeyedSubscript:]: unrecognized selector sent to instance 0x1d263a20
我不能使用这个设备,所以我编写代码来了解崩溃的位置。
if (![dictionaryRest[@"compliments"] isEqual:[NSNull null]]) {
NSMutableArray *array = [NSMutableArray new];
NSMutableArray *firstArray = [NSMutableArray new];
for (NSDictionary *dic in dictionaryRest[@"compliments"]) {
Compliment *compl = [Compliment new];
if (![dic[@"ID_promotions"] isEqual:[NSNull null]])
compl.ID = [dic[@"ID_promotions"] integerValue];
所以在最后 2 个字符串中,这个异常是。这是什么原因?所以我明白我需要使用
if ([dict objectForKey:[@"compliments"])
改为
if (![dict[@"compliments"] isEqual:[NSNull null]])
在所有其他情况下。
我现在进行测试,我的字典中有 ID:
【问题讨论】:
标签: ios objective-c json nsdictionary