JSON implicit assignment issue

Issue #171 resolved
Sergio Rossi created an issue

The implicit conversion of a JSON value fails when it is created not as an object but as a JSON base value.
The following code allows you to recreate the issue:

var j := JSON.Parse('{"Name":1.5}');
var h := JSON.Parse('3.5');

procedure Stuff1(a : Float);
begin
   PrintLn(a);
end;

procedure Stuff2(const a : Variant);
begin
   PrintLn(Float(a));
end;

var s : Float;

// works

s := j.Name;

PrintLn(s);

PrintLn(j.Name);
Stuff1(j.Name);
Stuff2(j.Name);

// don't works

s := h;

PrintLn(s);

PrintLn(h);
Stuff1(h);
Stuff2(h);

Comments (6)

  1. Eric Grange repo owner

    The snippet prints this here, which appears correct, unless I am missing something ?

    1.5
    1.5
    1.5
    1.5
    3.5
    3.5
    3.5
    3.5
    

  2. Sergio Rossi reporter

    That's weird. Running the script I get the following error: "Could not convert variant of type (Unknown) into type (Double)".
    As soon as I can, in the next few days, I will investigate better and give you more information.
    Thank you.

  3. Eric Grange repo owner

    Are you on a recent commit or some older version? Which Delphi version are you using?

  4. Sergio Rossi reporter

    Tested by Delphi XE2.
    But now I'm getting the doubt that I've compiled an old version of the library and not the most recent one. Maybe something like this could have happened.
    As soon as I can, I'll check it out and let you know.
    Thanks.

  5. Sergio Rossi reporter

    Today I had a chance to investigate thoroughly and found out that I had actually inadvertently compiled by an old version of the library, namely 2.3.
    Compiling instead using the latest version of the library, the script is executed without errors and as you reported.
    I apologize for my mistake.
    You can close the issue.
    Thank you.

  6. Log in to comment