[Issue 16432] New: JSON incorrectly parses to string
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Fri Aug 26 02:54:45 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=16432
Issue ID: 16432
Summary: JSON incorrectly parses to string
Product: D
Version: D2
Hardware: x86
OS: Mac OS X
Status: NEW
Severity: normal
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: sascha.orlov at gmail.com
Trying to copy a JSONValue via .toString.parseJSON, see
https://forum.dlang.org/thread/tsmllrkvdkuskroxcpcc@forum.dlang.org
found an error during conversion to string:
If a value is a floating type, which ends with a .0 during conversion to
string, the part after the point is cut away and the value is interpreted as an
integer afterwards.
void main()
{
import std.json;
import std.stdio;
string s = "{\"rating\": 3.0 }";
JSONValue j = parseJSON(s);
assert(j["rating"].type == JSON_TYPE.FLOAT);
writeln(j.toString);
j = j.toString.parseJSON;
assert(j["rating"].type != JSON_TYPE.FLOAT);
assert(j["rating"].type == JSON_TYPE.INTEGER);
}
If the value is like "3.1" the bug doesn't appear.
--
More information about the Digitalmars-d-bugs
mailing list