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?
Strictly speaking, json is untyped, so you can't send it as an integer, it has to be a string.
JSON only allows key names to be strings. Those strings can consist of numerical values.
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With