Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread Json array element separator not automatic
Wed, Aug 16 2017 12:04 AMPermanent Link

Stephen Barker

In my server (Delphi), I seem to have to manually add array element separators when using the TEWBJSONWriter class. Shouldn't this be automatic, or is this the correct way to do it?

uses EWBHTTPCommon...
TRequest = class(TObject)
 private
   FDB : TDBISAMDataBase;
   FSession : TDBISAMSession;
   FQuery : TDBISAMQuery;
   FJson : TEWBJSONWriter;
   FParams : TStringList;
...
procedure TRequest.EchoParameters;
var
 i : integer;
begin
 FJson.BeginObject;
 FJson.PropertyName('Received Parameters');
 if FParams.Count = 0 then
   FJson.NullValue
 else begin
   FJson.BeginArray(true);
   for i :=0 to FParams.Count-1 do begin
     if i > 0 then
       FJson.Separator;     <<---------- should be automatic?
     FJson.BeginObject;
     FJson.StringProperty(FParams.Names[i], FParams.Values[FParams.Names[i]]);
     FJson.EndObject;
   end;
   FJson.EndArray(true);
 end;
 FJson.EndObject;
end;

Steve
Wed, Aug 16 2017 5:02 AMPermanent Link

Matthew Jones

Stephen Barker wrote:

> Shouldn't this be automatic, or is this the correct way to do it?

The building of JSON is quite basic, so it is not automatic. If you try to get clever, you can catch yourself out, so the simple test is the easiest.
Thu, Aug 17 2017 1:48 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Stephen,

<< In my server (Delphi), I seem to have to manually add array element separators when using the TEWBJSONWriter class. Shouldn't this be automatic, or is this the correct way to do it? >>

No, they're not automatic.  I'll have to double-check, but I think the properties *do* handle this automatically and it was just a miss on the arrays.  If so, then I can log this as a breaking change for the next release (not build).

Tim Young
Elevate Software
www.elevatesoft.com
Image