Reputation: 6215
im parsing a JSON and cant seem to extract an integer. If i do
int secondsLeft = [secondsList objectForKey:@"SecondsToStop"];
if I do NSLog(@"%@",secondsLeft) it does however get outputted correctly in the console, but im unsure how to get a proper integer. Whats the proper way to parse numbers from a JSON object?
Upvotes: 12
Views: 11926
Reputation: 51735
Your JSON parsing framework probably stored the number as an NSNumber.
According to the NSNumber documentation, you can call intValue
on the number to get its value as a plain old int:
int secondsLeft = [[secondsList objectForKey:@"SecondsToTop"] intValue];
Upvotes: 23