Hi
How could I convert a string json to an delphi object, not an array
Type
Tuser = class
FCode : double;
FName : string;
FEmail : string;
end;
.....
procedure TDataModule1.WebHttpRequest1RequestResponse(Sender: TObject;
ARequest: TJSXMLHttpRequest; AResponse: string);
var
User : TUser;
begin
if AResponse = '200'
then begin
User := JS.parse(AResponse); ???????
end;
Thanks
end;
Bart
(Bart)
2
Hi,
Can you please try using TJSObject.Parse instead of JS.Parse?
Hi how can I do this, because
User := TJSObject.Parse(AResponse);
Return error in compile time.[Error] uCommonADO.pas(46): identifier not found "Parse"
Bart
(Bart)
4
My previous answer was indeed not correct.
Can you please have a look at the following sample to convert a string to a Delphi object?
Example:
procedure TForm1.WebFormCreate(Sender: TObject);
var
User: TUser;
oUser: TJSObject;
begin
User := TUser.Create;
oUser := TJSJSON.parseObject('{"FCode": 1, "FName": "name", "FEmail": "email"}');
User.FCode := strToFloat(string(oUser['FCode']));
User.FName := string(oUser['FName']);
User.FEmail := string(oUser['FEmail']);
console.log(User.FCode);
console.log(User.FName);
console.log(User.FEmail);
User.Free;
end;
Thanks, now I understanded.