#1 2016-10-12 22:39:28

warleyalex
Member
From: Sete Lagoas-MG, Brasil
Registered: 2013-01-20
Posts: 250

Extra square bracket

Following this post. Why does JSON have extra square bracket in the output?

{"result":[[1,2,3,4,"1001","1999"],[2,3,4,5,"1002","1998"],[3,4,5,6,"1003","1997"]]]}

  AFP.Init(TypeInfo(TFVs),AF);
  for i := 0 to 3 do begin
    F.Major := i;
    F.Minor := i+1;
    F.Release := i+2;
    F.Build := i+3;
    F.Main := IntToString(i+1000);
    F.Detailed := IntToString(2000-i);
    AFP.Add(F);
  end;

  test := AFP.SaveToJSON;
  result := RecordLoadJSON(F, pointer(test),TypeInfo(TFV));

Offline

#2 2016-10-13 15:46:58

warleyalex
Member
From: Sete Lagoas-MG, Brasil
Registered: 2013-01-20
Posts: 250

Re: Extra square bracket

huumm...
result := AFP.SaveToJSON(true);
it returns the correct output:
{"result":[[[0,1,2,3,"1000","2000"],[1,2,3,4,"1001","1999"],[2,3,4,5,"1002","1998"],[3,4,5,6,"1003","1997"]]]}

and...
result := RecordLoadJSON(F, pointer(test),TypeInfo(TFV));
it returns an extra square bracket.
{"result":[[1,2,3,4,"1001","1999"],[2,3,4,5,"1002","1998"],[3,4,5,6,"1003","1997"]]]}
The custom reader method return an extra ']' for last item of array, and you'll get a  Unexpected token ]

Offline

Board footer

Powered by FluxBB