Delphi-JsonToDelphiClass
Delphi-JsonToDelphiClass copied to clipboard
Problem with "Nested Arrays"
I use the generator on the site.
What is the reason for the lack of support for nested arrays? Personally, I solve it in the way below:
TVkKeyboardButtons = TArray<TVkKeyboardButton>; -- **and array there**
TVkKeyboard = class
private
FButtons: TArray<TVkKeyboardButtons>;
FOne_time: Boolean;
public
property buttons: TArray<TVkKeyboardButtons> read FButtons write FButtons; - **array there**
property one_time: Boolean read FOne_time write FOne_time;
destructor Destroy; override;
function ToJsonString: string;
class function FromJsonString(AJsonString: string): TVkKeyboard;
end;
Can you provide an example JSON with nested arrays?
Hi, Sure)
Result types: TVkKeyboardAction = class private FApp_id: Extended; FHash: string; FLabel: string; FPayload: string; FOwner_id: Extended; FType: string; //text, open_link, location, vkpay, open_app FLink: string; public property AppId: Extended read FApp_id write FApp_id; property Hash: string read FHash write FHash; property Link: string read FLink write FLink; property Payload: string read FPayload write FPayload; property&Label: string read FLabel write FLabel; property OwnerId: Extended read FOwner_id write FOwner_id; property&Type: string read FType write FType; function ToJsonString: string; class function FromJsonString(AJsonString: string): TVkKeyboardAction; end;
TVkKeyboardButton = class private FAction: TVkKeyboardAction; FColor: string; public property Action: TVkKeyboardAction read FAction write FAction; property Color: string read FColor write FColor; constructor Create; destructor Destroy; override; function ToJsonString: string; class function FromJsonString(AJsonString: string): TVkKeyboardButton; end;
TVkKeyboardButtons = TArray<TVkKeyboardButton>;
TVkKeyboard = class private FButtons: TArray<TVkKeyboardButtons>; FOne_time: Boolean; FInline: Boolean; FAuthor_id: Integer; public property Buttons: TArray<TVkKeyboardButtons> read FButtons write FButtons; property OneTime: Boolean read FOne_time write FOne_time; property&Inline: Boolean read FInline write FInline; property AuthorId: Integer read FAuthor_id write FAuthor_id; destructor Destroy; override; function ToJsonString: string; class function FromJsonString(AJsonString: string): TVkKeyboard; end; JSON: { "one_time": false, "buttons": [ [{ "action": { "type": "location", "payload": "{"button": "1"}" } }], [{ "action": { "type": "open_app", "app_id": 6979558, "owner_id": -181108510, "hash": "sendKeyboard", "label": "Отправить клавиатуру" } }], [{ "action": { "type": "vkpay", "hash": "action=transfer-to-group&group_id=181108510&aid=10" } }], [{ "action": { "type": "text", "payload": "{"button": "1"}", "label": "Negative" }, "color": "negative" }, { "action": { "type": "text", "payload": "{"button": "2"}", "label": "Positive" }, "color": "positive" }, { "action": { "type": "text", "payload": "{"button": "2"}", "label": "Primary" }, "color": "primary" }, { "action": { "type": "text", "payload": "{"button": "2"}", "label": "Secondary" }, "color": "secondary" } ] ] }
@HemulGM thankyou for your example I'll fix it in my fork of the project
https://github.com/JensBorrisholt/Delphi-JsonToDelphiClass