1

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?

Bin Chen
  • 61,507
  • 53
  • 142
  • 183

1 Answers1

1

TouchJSON will decode a number to NSNumber not NSInteger

NSNumber *user_id = [dict objectForKey:@"user_id"];
Michael Boselowitz
  • 3,012
  • 1
  • 19
  • 22
  • 1
    @BinChen same actually, still a NSNumber. To put the appropriate `NSNumber` into the dictionary you would do `NSNumber *n = [NSNumber numberWithBool:YES];`, likewise when you deserialize and you have the corresponding `NSNumber` you would do `[n boolValue];`. – Michael Boselowitz Jun 25 '12 at 17:15