Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » Elevate Web Builder Technical Support » Support Forums » Elevate Web Builder General » View Thread |
Messages 1 to 4 of 4 total |
Use TReader to read the EWB users |
Fri, Apr 5 2024 2:51 PM | Permanent Link |
George | Hi everybody,
I am trying to read the JSON received from the server (using the /administration?method=getusers request), which I receive successfully, and I read each property using the TReader and insert it into a table. All properties are read successfully except from the Roles. What am I missing something in my code? I appreciate any help on this. THrmUser = class(TPersistent) private FName: String; FActive: Boolean; FFullName: String; FEmailAddress: String; FLoginStartTime : Integer; FLoginEndTime : Integer; FLocked : Boolean; FLockReleaseTime : Integer; FRoles : String; published property Name: String read FName write FName; property Active: Boolean read FActive write FActive; property FullName: String read FFullName write FFullName; property EmailAddress: String read FEmailAddress write FEmailAddress; property LoginStartTime: Integer read FLoginStartTime write FLoginStartTime; property LoginEndTime: Integer read FLoginEndTime write FLoginEndTime; property Locked: Boolean read FLocked write FLocked; property LockReleaseTime: Integer read FLockReleaseTime write FLockReleaseTime; property Roles: String read FRoles write FRoles; end; procedure TForm1.ReadHrmUsersFromJSON(sJSON : String); var Reader: TReader; HrmUser: THrmUser; begin Reader := TReader.Create; try HrmUser := THrmUser.Create; Users.Open; try with Reader do begin Initialize(sJSON); BeginObject; ReadPropertyName('Users'); MainForm.MultiLineEdit1.Lines.Add('Reading users'); SkipPropertyName; end; HrmUser.Load(Reader); while Reader.MoreArrayElements do begin HrmUser.Load(Reader); with Users do begin Users.insert; Columns['Name'].AsString := HrmUser.Name; Columns['Active'].AsBoolean := HrmUser.Active; Columns['FullName'].AsString := HrmUser.FullName; Columns['EmailAddress'].AsString := HrmUser.EmailAddress; Columns['Locked'].AsBoolean := HrmUser.Locked; Columns['Roles'].AsString := HrmUser.Roles; Save; end; end; finally HrmUser.Free; end; finally Reader.Free; end; end; For easy reference this is the JSON response with the users: { "Users": [ { "Name": "ABC", "Active": true, "FullName": "ABC", "EmailAddress": "abc@gmail.com", "LoginStartTime": -2209161600000, "LoginEndTime": -2209075201000, "Locked": false, "LockReleaseTime": 0, "Roles": [ { "Name": "Employee" }, { "Name": "HRMAdmin" } ] }, { "Name": "Administrator", "Active": true, "FullName": "Administrator User", "EmailAddress": "", "LoginStartTime": -2209161600000, "LoginEndTime": -2209075201000, "Locked": false, "LockReleaseTime": 0, "Roles": [ { "Name": "Administrators" } ] } ] } I would greatly appreciate any help. George |
Mon, Apr 8 2024 5:29 AM | Permanent Link |
Walter Matte Tactical Business Corporation | Roles is an Array - not a String;
|
Tue, Apr 9 2024 12:36 PM | Permanent Link |
George | Thanks Walter I will try that
|
Thu, Apr 11 2024 2:49 AM | Permanent Link |
Ralf Mimoun | Define TRoles as a collection of TRole (TCollectionItem). That should do the trick,
|
This web page was last updated on Wednesday, August 14, 2024 at 02:26 AM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |