Take the following piece of code:
NSError *error;
NSString *myJSONString = @\"{ \\\"foo\\\" : 0.1}\";
NSData *jsonData = [myJSONString dataUsingEncoding:NSUTF8St
To answer the question in the title: No, it doesn't, it creates NSNumber
objects. You can easily test this:
NSArray *a = @[[NSDecimalNumber decimalNumberWithString:@"0.1"]];
NSData *data = [NSJSONSerialization dataWithJSONObject:a options:0 error:NULL];
a = [NSJSONSerialization JSONObjectWithData:data options:0 error:NULL];
NSLog(@"%@", [a[0] class]);
will print __NSCFNumber
.
You can convert that NSNumber
object to an NSDecimalNumber
with [NSDecimalNumber decimalNumberWithDecimal:[number decimalValue]]
, but according to the docs for decimalValue
The value returned isn’t guaranteed to be exact for float and double values.