#2 mORMot 1 » TDocVariant: strange behavor to create JSON » 2019-02-18 12:55:53

nobug
Replies: 2

While trying to create JSON using TDocVariant, I encounter a problem. The following test shows the problem.

program test;

{$APPTYPE CONSOLE}

uses
  SynCommons;


    function f2(aJO: Variant): string;
    begin
      aJO.ip2  := aJO.ip1;
      aJO.ip3  := aJO.ip1;
      result := VariantSaveJSON(aJO);
    end;

    function f1(aStr: string): string;
    var
      JO: variant;
    begin
      JO := _Json(aStr);
      JO.p := 'ss';
      JO.ip1 := '192.168.1.1';
      Result := f2(JO);
    end;

var
  Str1, Str2: string;

begin
  Str1 := '{"a":1,"b":2,"c":3,"d":4,"e":5,"f":6,"g":7,"h":8,"i":9,"j":10,"k":11,"l":12,"m":13,"n":14}';
  Writeln(f1(Str1));

  Writeln('======================================================');

  Str2 := '{"a":1,"b":2,"c":3,"d":4,"e":5,"f":6,"g":7,"h":8,"i":9,"j":10,"k":11,"l":12,"m":13,"n":14,"o":15}';
  Writeln(f1(Str2));

  readln;
end.

Run under Win32, it is ok!  Under Win64,  the result is:

{"a":1,"b":2,"c":3,"d":4,"e":5,"f":6,"g":7,"h":8,"i":9,"j":10,"k":11,"l":12,"m":13,"n":14,"p":"ss","ip1":"192.168.1.1","ip2":"192.168.1.1","ip3":"192.168.1.1"}
======================================================
{"a":1,"b":2,"c":3,"d":4,"e":5,"f":6,"g":7,"h":8,"i":9,"j":10,"k":11,"l":12,"m":13,"n":14,"o":15,"p":"ss","ip1":"192.168.1.1","ip2":null,"ip3":"192.168.1.1"}

The result of the function call:  Writeln(f1(Str2))  is not correct,  the corresponding value of "ip2" is null !
Is there something wrong in my test?

Thanks.

Board footer

Powered by FluxBB