gpt4 book ai didi

iphone - 只有 iOS 7 崩溃 [NSNull intValue] : unrecognized selector sent to instance

转载 作者:技术小花猫 更新时间:2023-10-29 11:09:22 25 4
gpt4 key购买 nike

我想从 JSON 服务获取数据。从 JSON 值获取数据时,只有 iOS 7 版本崩溃。它从下面的 JSON 服务返回:

{
voteAverageRating = 0;
voteCount = 0;
}

我的代码

int voteCount = [listDic objectForKey:@"voteCount"] intValue] ;

_LB_voteNumber.text = [NSString stringWithFormat:@"(%i)",voteCount];

它适用于 iOS 5、5.1、6.0、6.1,但它仅在 iOS7 版本上崩溃。它给出了这个错误:

0x00098117 _mh_execute_header [NSNull intValue]: unrecognized selector sent to instance

然后我在下面更改了我的代码;

NSString *voteCount = [listDic objectForKey:@"voteCount"] ;

_LB_voteNumber.text = [NSString stringWithFormat:@"(%@)",voteCount];

何时运行此代码。它再次崩溃只有 iOS 7 版本。它给出了这个错误:

0x00098117 _mh_execute_header [NSNull length]: unrecognized selector sent to instance

我该如何解决这个问题?

最佳答案

在从 JSON 访问值之前进行检查,例如,

if([NSNull null] != [listDic objectForKey:@"voteCount"]) {
NSString *voteCount = [listDic objectForKey:@"voteCount"];
/// ....
}

检查的原因是,像 NSDictionary 这样的集合对象不允许值是 nil,因此它们被存储为 null。将 intValue 传递给 NSNull 将不起作用,因为它无法识别此选择器。

希望对您有所帮助!

关于iphone - 只有 iOS 7 崩溃 [NSNull intValue] : unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18887727/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com