简体   繁体   中英

Error converting int into NSNumber

I am fetching data from the web, and I am having problems with the numbers that are returned. 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. 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. You cannot cast it into an int, it must be unboxed first.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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