jfisk
jfisk

Reputation: 6215

how to get an integer from JSON

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

Answers (1)

s4y
s4y

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

Related Questions