Bin Chen
Bin Chen

Reputation: 63369

get touchJson data for int type

I am using touchJson to deserialize my json from server. My json is like below:

{"text":"abc", "user_id":12345}

After deserializing, I use below code to get the Json values:

NSString *text = [dict objectForKey:@"text"];

This is simple because the data is string, but for "user_id" what type should I use to decode, is it correct?:

NSInteger *user_id = [dict objectForKey:@"user_id"];

If not, what's the right way to hold the integer json type?

Upvotes: 1

Views: 56

Answers (1)

Michael Boselowitz
Michael Boselowitz

Reputation: 3006

TouchJSON will decode a number to NSNumber not NSInteger

NSNumber *user_id = [dict objectForKey:@"user_id"];

Upvotes: 1

Related Questions