#1 Re: mORMot 1 » JSON serialize TObject » 2015-10-22 06:54:00

Thanks for reply smile

Inherited by TPersistent is one and two propery not public but published

  TTestJson = class(TPersistent)
  private
    FAge: Integer;
    FFirstName: string;
    FLastName: string;
    procedure SetAge(const Value: Integer);
    procedure SetFirstName(const Value: string);
    procedure SetLastName(const Value: string);
  published
    property Age: Integer read FAge write SetAge;
    property FirstName: string read FFirstName write SetFirstName;
    property LastName: string read FLastName write SetLastName;
  end;

Once again thanks for help and for mORMot smile

#2 mORMot 1 » JSON serialize TObject » 2015-10-22 05:39:41

mitring
Replies: 2

Hi I have problem with ObjectToJSON using SynCrossPlatformJSON.pas

  TTestJson = class(TObject)
  private
    FAge: Integer;
    FFirstName: string;
    FLastName: string;
    procedure SetAge(const Value: Integer);
    procedure SetFirstName(const Value: string);
    procedure SetLastName(const Value: string);
  public
    property Age: Integer read FAge write SetAge;
    property FirstName: string read FFirstName write SetFirstName;
    property LastName: string read FLastName write SetLastName;
  end;

{...}

var
  S1: TTestJson;
begin
  S1 := TTestJson.Create;
  try
    S1.Age       := 30;
    S1.FirstName := 'Peter';
    S1.LastName  := 'My Last Name';

    Memo1.Text := ObjectToJSON(S1); // <-- return 'null'
  finally
    S1.Free;
  end;
end;

How to correctly use ObjectToJSON using SynCrossPlatformJSON.pas

Thanks for help.

Board footer

Powered by FluxBB