prostock
prostock

Reputation: 9555

NSNumber integerValue returns incorrect value

I have a very large integer returned by a json string from my server to my iphone app. I usually use:

[results objectForKey:@"id"]

and things work fine but with a very large "id" the results don't match what was sent. what is the standard method to get the integer value of the object returned by json?

Upvotes: 1

Views: 380

Answers (1)

PengOne
PengOne

Reputation: 48406

Try with

  NSLog(@"%lld", [[results objectForKey@"id"] longLongValue]);

An int will have value between

INT_MIN: -2147483648
INT_MAX: 2147483647

and a long long will have value between

LLONG_MIN: -9223372036854775808
LLONG_MAX: 9223372036854775807

If its longer than that, you might try manipulating it as a string.

Upvotes: 2

Related Questions