digitalmars.D.learn - JSONValue floating and 42
- Andre (16/16) Apr 19 2016 Hi,
- Edwin van Leeuwen (10/12) Apr 19 2016 This is the correct option. Something like:
- Andre (5/17) Apr 19 2016 I will do so. Thanks.
Hi, I have to deal with a JSON like this [{"value":42},{"value":1e+100}] Value is a floating number, but the providing system does not write 42 as 42.00. While trying to get the value with .floating, I get an exception because 42 is not a floating value. I try to understand what is the issue here. -> Does the system violates the JSON Standard, and it should deliver 42.00? -> .floating should be enhanced to handle 42? -> I need to analyze every value whether it is a floating or an integer? Kind regards André
Apr 19 2016
On Tuesday, 19 April 2016 at 13:44:08 UTC, Andre wrote:-> I need to analyze every value whether it is a floating or an integer?This is the correct option. Something like: double f; if (j["value"].type == JSON_TYPE.INTEGER) f = j["value"].integer.to!float; else f = j["value"].floating; There are also a number of libraries available that make dealing with json a bit easier: code.dlang.org/search?q=json
Apr 19 2016
On Tuesday, 19 April 2016 at 13:58:05 UTC, Edwin van Leeuwen wrote:On Tuesday, 19 April 2016 at 13:44:08 UTC, Andre wrote:I will do so. Thanks. Kind regards André-> I need to analyze every value whether it is a floating or an integer?This is the correct option. Something like: double f; if (j["value"].type == JSON_TYPE.INTEGER) f = j["value"].integer.to!float; else f = j["value"].floating; There are also a number of libraries available that make dealing with json a bit easier: code.dlang.org/search?q=json
Apr 19 2016