Ver Mensaje Individual
  #5  
Antiguo 10-08-2018
Avatar de lbidi
lbidi lbidi is offline
Miembro
 
Registrado: oct 2003
Ubicación: Montevideo- URUGUAY
Posts: 417
Reputación: 21
lbidi Va por buen camino
Hola neftali .. muchas gracias por compartir ese codigo y el sitio para crear esas clases. Es fantastico.

Ahora te pido una ayuda para comprender como "leer" los objetos de dicha clase con este Json

[
{
"id": 71,
"companyId": 4,
"name": "Leo b",
"email": null,
"takeAway": false,
"deviceId": 457,
"state": "NEW",
"dateNew": 1533517288534,
"street": "Mac eachen",
"total": 332,
"number": "1324",
"betweenStreet": "",
"apartmentNumber": "",
"telephone": "099127695",
"annotation": null,
"products": [
{
"comment": null,
"code": 709,
"amount": 2,
"name": "PIZZETA A LA SALSA",
"total": 185,
"productItemsName": []
}
],
"dateInitProcess": null,
"timeToFinishProcess": null,
"dateFinish": null,
"dateCancel": null,
"cancelBecause": null
},
{
"id": 70,
"companyId": 4,
"name": "Leo b",
"email": null,
"takeAway": false,
"deviceId": 457,
"state": "NEW",
"dateNew": 1533517256850,
"street": "Mac eachen",
"total": 170,
"number": "1324",
"betweenStreet": "",
"apartmentNumber": "",
"telephone": "099127695",
"annotation": null,
"products": [
{
"comment": null,
"code": 102,
"amount": 1,
"name": "PIZZA",
"total": 75,
"productItemsName": []
},
{
"comment": null,
"code": 101,
"amount": 1,
"name": "MUZZARELLA",
"total": 115,
"productItemsName": []
}
],
"dateInitProcess": null,
"timeToFinishProcess": null,
"dateFinish": null,
"dateCancel": null,
"cancelBecause": null
},
]

Me ha definido esta clase pero no me doy cuenta como utilizarla. Muchas gracias desde ya !!!!

Código Delphi [-]
unit JSonClass;

{*******************************************************************************
    Generated By   : JsonToDelphiClass - 0.65 
    Project link   : https://github.com/PKGeorgiev/Delphi-JsonToDelphiClass
    Generated On   : 2018-08-10 16:24:40

    Created By     : Petar Georgiev - (http://pgeorgiev.com) 
    Adapted Web By : Marlon Nardi - (http://jsontodelphi.com)
*******************************************************************************}

interface

uses Generics.Collections, Rest.Json;

type

TProductItemsNameClass = class
private
public
  function ToJsonString: string;
  class function FromJsonString(AJsonString: string): TProductItemsNameClass;
end;

TProductsClass = class
private
  FAmount: Extended;
  FCode: Extended;
  FName: String;
  FProductItemsName: TArray;
  FTotal: Extended;
public
  property amount: Extended read FAmount write FAmount;
  property code: Extended read FCode write FCode;
  property name: String read FName write FName;
  property productItemsName: TArray read FProductItemsName write FProductItemsName;
  property total: Extended read FTotal write FTotal;
  destructor Destroy; override;
  function ToJsonString: string;
  class function FromJsonString(AJsonString: string): TProductsClass;
end;

TItemClass = class
private
  FApartmentNumber: String;
  FBetweenStreet: String;
  FCompanyId: Extended;
  FDateNew: Extended;
  FDeviceId: Extended;
  FId: Extended;
  FName: String;
  FNumber: String;
  FProducts: TArray;
  FState: String;
  FStreet: String;
  FTakeAway: Boolean;
  FTelephone: String;
  FTotal: Extended;
public
  property apartmentNumber: String read FApartmentNumber write FApartmentNumber;
  property betweenStreet: String read FBetweenStreet write FBetweenStreet;
  property companyId: Extended read FCompanyId write FCompanyId;
  property dateNew: Extended read FDateNew write FDateNew;
  property deviceId: Extended read FDeviceId write FDeviceId;
  property id: Extended read FId write FId;
  property name: String read FName write FName;
  property number: String read FNumber write FNumber;
  property products: TArray read FProducts write FProducts;
  property state: String read FState write FState;
  property street: String read FStreet write FStreet;
  property takeAway: Boolean read FTakeAway write FTakeAway;
  property telephone: String read FTelephone write FTelephone;
  property total: Extended read FTotal write FTotal;
  destructor Destroy; override;
  function ToJsonString: string;
  class function FromJsonString(AJsonString: string): TItemClass;
end;

TRootClass = class
private
  FItems: TArray;
public
  property Items: TArray read FItems write FItems;
  destructor Destroy; override;
  function ToJsonString: string;
  class function FromJsonString(AJsonString: string): TRootClass;
end;

implementation

{TProductItemsNameClass}

function TProductItemsNameClass.ToJsonString: string;
begin
  result := TJson.ObjectToJsonString(self);
end;

class function TProductItemsNameClass.FromJsonString(AJsonString: string): TProductItemsNameClass;
begin
  result := TJson.JsonToObject(AJsonString)
end;

{TProductsClass}

destructor TProductsClass.Destroy;
var
  LproductItemsNameItem: TProductItemsNameClass;
begin

 for LproductItemsNameItem in FProductItemsName do
   LproductItemsNameItem.Free;

  inherited;
end;

function TProductsClass.ToJsonString: string;
begin
  result := TJson.ObjectToJsonString(self);
end;

class function TProductsClass.FromJsonString(AJsonString: string): TProductsClass;
begin
  result := TJson.JsonToObject(AJsonString)
end;

{TItemClass}

destructor TItemClass.Destroy;
var
  LproductsItem: TProductsClass;
begin

 for LproductsItem in FProducts do
   LproductsItem.Free;

  inherited;
end;

function TItemClass.ToJsonString: string;
begin
  result := TJson.ObjectToJsonString(self);
end;

class function TItemClass.FromJsonString(AJsonString: string): TItemClass;
begin
  result := TJson.JsonToObject(AJsonString)
end;

{TRootClass}

destructor TRootClass.Destroy;
var
  LItemsItem: TItemClass;
begin

 for LItemsItem in FItems do
   LItemsItem.Free;

  inherited;
end;

function TRootClass.ToJsonString: string;
begin
  result := TJson.ObjectToJsonString(self);
end;

class function TRootClass.FromJsonString(AJsonString: string): TRootClass;
begin
  result := TJson.JsonToObject(AJsonString)
end;

end.
Responder Con Cita