NSJSONSerialization output number as floating?

I am using NSJSONSerialization to convert a dictionary to JSON.

If I include NSDecimalNumber (== 0) in this dictionary, it is output as 0 . This is not true. 0 is an int. I need it to output as 0.0 .

This is what I do:

 NSDecimalNumber *decimal = [[NSDecimalNumber alloc] initWithFloat:0.0f]; // when fed into NSJSONSerialization it outputs as 0 

Is there any way to output as 0.0 ?

OR Am I mistaken in my assumption? Is 0 valid float?

+4
source share
1 answer

There is no way to influence how NSJSONSerialization displays numbers. But you really should not worry about that. JSON does not distinguish between different types of numbers, so you should always accept numbers with and without a decimal point, no matter what type of number you are doing with.

+5
source

Source: https://habr.com/ru/post/1480768/


All Articles