I’m working with an API that returns a JSON dictionary. One of the keys is “Variant Hash”, and the corresponding data is an integer like this: -7331108254952843887 or 6209894088655053576. I’m assuming this is a long long value. I’m serializing this data with NSCoder, and I’m not sure which encodeValue: method to use. There is no encodeLongLongValue:forKey:.
Also, doing NSLog(@"%@",returnedDictionary); displays the entire dictionary structure, but using objectForKey: doesn’t work because the corresponding value for the key Variant Hash is not an object.
How can I get the data out of the dictionary, and how should I store this with NSCoder?
Depending on the JSON parser you’re using, the number is being stored in the dictionary as an NSNumber, NSDecimalNumber, NSString, or NSValue. NSNumber (or NSDecimalNumber, which is a subclass) is probably the most likely, but I’d check your parser’s documentation or code.
Assuming that’s the case, you’d get the value as such.
I’d probably implement some type checking in this code, just to be safe.
NSNumber conforms to NSCoding, so you can use the numberValue instance to also do your encoding.