For a simple Object, it's easy, but if this object contains TLists, it doesn't work.
If my webservice returns a TClient :
TAddress = class
Street: string;
number: integer;
end;
TClient = class
firstName: string;
lastName: string;
AddressList: TList<TAddress>;
end;
which gives in JSON :
{
"$id": 1,
"firstName": "Neil",
"lastName": "Armstrong",
"AddressList": [
{
"$id": 2,
"Street": "Mainstreet",
"number": 1
},
{
"$id": 3,
"Street": "First avenue",
"number": 2
}
]
}
I can get firstName & lastName, but not the Addresslist :
procedure OnResult(Response: TXDataClientResponse);
var
MyClient: TClient;
JSObj: TJSObject;
begin
JsObj:=Response.ResultAsObject;
MyClient := TClient.Create;
MyClient.AddressList:=TList.create;
MyClient := TClient(JSObj);
Showmessage(MyClient.firstName); // OK
Showmessage(MyClient.AddressList[0].Street) // BUG
end;
Is there another way to convert a TJSObject to a TObject?