You are not logged in.
Pages: 1
Thanks, didn't see the warnings. Works now.
Hi,
Im new to Delphi and i am assiged to webenable the Delphi project here. We like to connect my C# ASP services to the Delphi program.
In my code below ObjectToJSON works, but not the opposite way; so no object is created or filled with the JSONContent. What ami i doing wrong.
Thanks
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, generics.collections, mORMot, mORMotSQLite3, SynSQLite3Static, mORMotHttpServer, SynCommons, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
SampleClass = class(TSynPersistent)
private
Fstr: string;
Fn: integer;
published
property Str: String read Fstr write Fstr;
published
property n: integer read Fn write Fn;
end;
var
Form1: TForm1;
c: SampleClass;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
JSONContent: string;
newObj: SampleClass;
utf8: PUTF8char;
JsonResult: boolean;
begin
c := SampleClass.Create;
c.Str := 'String';
c.n := 99;
JSONContent := ObjectToJSON(c);
Memo1.lines.Add(JSONContent);
newObj := SampleClass.Create;
TJSONSerializer.RegisterClassForJSON(SampleClass);
utf8 := JSONToObject(newObj, pointer(JSONContent), JsonResult, SampleClass, [j2oSetterNoCreate]);
Memo1.lines.Add('JSONToObject result: ' + JsonResult.ToString);
// JsonResult is false here, newObj is not filled.
JSONContent := ObjectToJSON(newObj);
Memo1.lines.Add(JSONContent)
end;
end.
Pages: 1