1

Topic: Json To Delphi Class

http://jsontodelphi.com/
Generate delphi classes from json.
It is made on UniGui.
Cool.

2

Re: Json To Delphi Class

And..... What for? [img=http://forum.podolsk.ru/images/smilies/confused.gif]

3

Re: Json To Delphi Class

You translate XML in JSON and "the task is shown to already solved" - In

4

Re: Json To Delphi Class

defecator;
It is possible to work with arbitrary JSON on the basis of an object model  the automatic machine.

5

Re: Json To Delphi Class

rgreat wrote:

It is possible to work with arbitrary JSON on the basis of an object model  the automatic machine.

You do not have anything, and suddenly model... Can on the contrary? smile

6

Re: Json To Delphi Class

Dmitry Arefiev;
Not-not-not! You have  a sample json and "suddenly" - model! wink

7

Re: Json To Delphi Class

[spoiler we Take json: http://json.org/example.html]

 {"menu": {
"id": "file";
"value": "File";
"popup": {
"menuitem": [
{"value": "New", "onclick": "CreateNewDoc ()"};
{"value": "Open", "onclick": "OpenDoc ()"};
{"value": "Close", "onclick": "CloseDoc ()"}
]
}
}}

[/spoiler]
[spoiler It is exhausted in http://jsontodelphi.com/, we Receive:]

unit RootUnit;
{*******************************************************************************
Generated By: JsonToDelphiClass - 0.65
Project link: https://github.com/PKGeorgiev/Delphi-JsonToDelphiClass
Generated On: 2016-12-09 1:25:23 PM
Created By: Petar Georgiev - 2014 (http://pgeorgiev.com)
Adapted Web By: Marlon Nardi - 2016 (http://jsontodelphi.com)
*******************************************************************************}
interface
uses Generics. Collections, Rest. Json;
type
TMenuitemClass = class
private
FOnclick: String;
FValue: String;
public
property onclick: String read FOnclick write FOnclick;
property value: String read FValue write FValue;
function ToJsonString: string;
class function FromJsonString (AJsonString: string): TMenuitemClass;
end;
TPopupClass = class
private
FMenuitem: TArray <TMenuitemClass>;
public
property menuitem: TArray <TMenuitemClass> read FMenuitem write FMenuitem;
destructor Destroy; override;
function ToJsonString: string;
class function FromJsonString (AJsonString: string): TPopupClass;
end;
TMenuClass = class
private
FId: String;
FPopup: TPopupClass;
FValue: String;
public
property id: String read FId write FId;
property popup: TPopupClass read FPopup write FPopup;
property value: String read FValue write FValue;
constructor Create;
destructor Destroy; override;
function ToJsonString: string;
class function FromJsonString (AJsonString: string): TMenuClass;
end;
TRootClass = class
private
FMenu: TMenuClass;
public
property menu: TMenuClass read FMenu write FMenu;
constructor Create;
destructor Destroy; override;
function ToJsonString: string;
class function FromJsonString (AJsonString: string): TRootClass;
end;
implementation
{TMenuitemClass}
function TMenuitemClass. ToJsonString: string;
begin
result: = TJson. ObjectToJsonString (self);
end;
class function TMenuitemClass. FromJsonString (AJsonString: string): TMenuitemClass;
begin
result: = TJson. JsonToObject <TMenuitemClass> (AJsonString)
end;
{TPopupClass}
destructor TPopupClass. Destroy;
var
LmenuitemItem: TMenuitemClass;
begin
for LmenuitemItem in FMenuitem do
LmenuitemItem.free;
inherited;
end;
function TPopupClass. ToJsonString: string;
begin
result: = TJson. ObjectToJsonString (self);
end;
class function TPopupClass. FromJsonString (AJsonString: string): TPopupClass;
begin
result: = TJson. JsonToObject <TPopupClass> (AJsonString)
end;
{TMenuClass}
constructor TMenuClass. Create;
begin
inherited;
FPopup: = TPopupClass. Create ();
end;
destructor TMenuClass. Destroy;
begin
FPopup.free;
inherited;
end;
function TMenuClass. ToJsonString: string;
begin
result: = TJson. ObjectToJsonString (self);
end;
class function TMenuClass. FromJsonString (AJsonString: string): TMenuClass;
begin
result: = TJson. JsonToObject <TMenuClass> (AJsonString)
end;
{TRootClass}
constructor TRootClass. Create;
begin
inherited;
FMenu: = TMenuClass. Create ();
end;
destructor TRootClass. Destroy;
begin
FMenu.free;
inherited;
end;
function TRootClass. ToJsonString: string;
begin
result: = TJson. ObjectToJsonString (self);
end;
class function TRootClass. FromJsonString (AJsonString: string): TRootClass;
begin
result: = TJson. JsonToObject <TRootClass> (AJsonString)
end;
end.

[/spoiler]

8

Re: Json To Delphi Class

rgreat wrote:

defecator;
It is possible to work with arbitrary JSON on the basis of an object model  the automatic machine.

source codes at everyone  - it is very fascinating.
Whether more cleverly to build classes according to business requirements, and json to use according to the destination - for a data interchange?
Thus ()  only the necessary data members.
And to work with "arbitrary" json - objects for a long time almost all libraries, for this purpose intended are able.

9

Re: Json To Delphi Class

rgreat wrote:

Not-not-not! You have  a sample json and "suddenly" - model! wink

It is necessary to understand only model of that if it is an unknown animal...
It not model, and  a skeleton smile

10

Re: Json To Delphi Class

Companion the low sergeant;
for client SOAP the web of service you also strains wrappers?
And after all it almost too most.

11

Re: Json To Delphi Class

Dmitry Arefiev;
It yes. The skeleton should be studied beforehand. And its missing parts are added in .:]

12

Re: Json To Delphi Class

rgreat wrote:

And its missing parts are added in .:]

At the nature it on the contrary...

13

Re: Json To Delphi Class

At  generally much through... Unnaturally in general. smile

14

Re: Json To Delphi Class

rgreat wrote:

At  generally much through... Unnaturally in general. smile

It is psychological singularity of programmers to consider that it so. And an essence -  from itself the organizations.
And generally... Well and generally... smile

15

Re: Json To Delphi Class

rgreat wrote:

the Companion the low sergeant;
for client SOAP the web of service you also strains wrappers?
And after all it almost too most.

Well, if the same - .
I permit.

16

Re: Json To Delphi Class

[img=http://cs.pikabu.ru/images/big_size_comm/2013-02_4/13611055258955.jpg]