简体   繁体   English

将int转换为NSNumber时出错

[英]Error converting int into NSNumber

I am fetching data from the web, and I am having problems with the numbers that are returned. 我正在从Web上获取数据,并且返回的数字有问题。 For example, when the int 1 is returned from the server, and I try and convert that int to a NSNumber, the value of the NSNumber is 151241152. The number is slightly different every time, but it is always over 1 billion. 例如,当从服务器返回int 1时,我尝试将该int转换为NSNumber,则NSNumber的值为151241152。该数字每次都略有不同,但始终超过10亿。 Here is my code: 这是我的代码:

int agrees = (int)[info objectForKey:kWaveAgrees];
wave.numberOfAgrees = [NSNumber numberWithInt:agrees];

Does anyone know why this is happening? 有人知道为什么会这样吗?

NSNumber is an object. NSNumber是一个对象。 You cannot cast it into an int, it must be unboxed first. 您不能将其转换为整数,必须先将其拆箱。

int agrees = [[info objectForKey:kWaveAgrees] intValue]; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM