Konuyu Oyla:
  • Derecelendirme: 0/5 - 0 oy
  • 1
  • 2
  • 3
  • 4
  • 5
json parse
#15
Öncelikle herkese merhabalar... Aşağıdaki JSON'u parse etmeyi bir türlü beceremedim. Gerek forumlarda gerekse netteki araştırmalarım ve denemelerim sonuçsuz kaldı. Çözüm adına önerilerinizi bekler, iyi çalışmalar dilerim...

[
  {
     "id":"5ff06fbd36781450367e2a41",
     "status":400,
     "isScheduled":false,
     "confirmationId":"r392",
     "client":{
        "id":"5f9182d0124a29b457413b28",
        "name":"Mehmet P.",
        "location":{
           "lat":41.0197888,
           "lon":29.040162
        },
        "clientPhoneNumber":"+90 (850) 346-9388882 / 7748873",
        "contactPhoneNumber":"+90 (850) 215-150000",
        "deliveryAddress":{
           "id":"5ff06ebfc5269c7a0345db9a",
           "address":"Altunizade Mah. - Yetimhane Sok., No:1G",
           "aptNo":"",
           "floor":"",
           "doorNo":"",
           "description":""
        }
     },
     "courier":{
        "id":"5dc073faf4d28e09f0377cad",
        "status":100,
        "name":"Restoran Kurye",
        "location":{
           "lat":41.0771112,
           "lon":29.0312168
        }
     },
     "products":[
        {
           "id":"5ff06fbe36781490857e2a44",
           "imageURL":"",
           "wideImageURL":"",
           "count":2,
           "product":"5ede1eddc637a70fae6a4c8b",
           "chainProduct":"",
           "name":{
              "tr":"Ayran",
              "en":"Ayran"
           },
           "price":3,
           "optionPrice":0,
           "priceWithOption":3,
           "totalPrice":6,
           "totalOptionPrice":0,
           "totalPriceWithOption":6,
           "optionCategories":[
               
            ],
           "displayInfo":{
              "title":{
                 "tr":"Ayran",
                 "en":"Ayran"
              },
              "options":{
                 "tr":[
                     
                  ],
                 "en":[
                     
                  ]
              }
           }
        }
     ],
     "clientNote":"",
     "totalPrice":6,
     "checkoutDate":"2021-01-02T14:01:00.793Z",
     "deliveryType":2,
     "doNotKnock":false,
     "isEcoFriendly":false,
     "restaurant":{
        "id":"5ede1dfac637a7cff96a4c7b"
     },
     "paymentMethod":4,
     "paymentMethodText":{
        "en":"On Delivery Cash Payment",
        "tr":"Kap�da Nakit ile �deme"
     }
  }
]

Kullandığım Unit de bu şekildedir... Ancak bu Unit'i kullanarak dataları çekebileceğim fonksiyonu bir türlü yazamadım....


unit RootUnit;

interface

uses
 Pkg.Json.DTO, System.Generics.Collections, REST.Json.Types;

{$M+}

type
 TPaymentMethodTextDTO = class
 private
   FEn: string;
   FTr: string;
 published
   property En: string read FEn write FEn;
   property Tr: string read FTr write FTr;
 end;
 
 TRestaurantDTO = class
 private
   FId: string;
 published
   property Id: string read FId write FId;
 end;
 
 TEnDTO = class
 end;
 
 TTrDTO = class
 end;
 
 TOptionsDTO = class
 private
   [JSONName('en')]
   FEnArray: TArray<TEnDTO>;
   [GenericListReflect]
   FEn: TObjectList<TEnDTO>;
   [JSONName('tr')]
   FTrArray: TArray<TTrDTO>;
   [GenericListReflect]
   FTr: TObjectList<TTrDTO>;
   function GetTr: TObjectList<TTrDTO>;
   function GetEn: TObjectList<TEnDTO>;
 published
   property En: TObjectList<TEnDTO> read GetEn;
   property Tr: TObjectList<TTrDTO> read GetTr;
   destructor Destroy; override;
 end;
 
 TTitleDTO = class
 private
   FEn: string;
   FTr: string;
 published
   property En: string read FEn write FEn;
   property Tr: string read FTr write FTr;
 end;
 
 TDisplayInfoDTO = class
 private
   FOptions: TOptionsDTO;
   FTitle: TTitleDTO;
 published
   property Options: TOptionsDTO read FOptions write FOptions;
   property Title: TTitleDTO read FTitle write FTitle;
 public
   constructor Create;
   destructor Destroy; override;
 end;
 
 TOptionCategoriesDTO = class
 end;
 
 TNameDTO = class
 private
   FEn: string;
   FTr: string;
 published
   property En: string read FEn write FEn;
   property Tr: string read FTr write FTr;
 end;
 
 TProductsDTO = class
 private
   FChainProduct: string;
   FCount: Integer;
   FDisplayInfo: TDisplayInfoDTO;
   FId: string;
   FImageURL: string;
   FName: TNameDTO;
   [JSONName('optionCategories')]
   FOptionCategoriesArray: TArray<TOptionCategoriesDTO>;
   [GenericListReflect]
   FOptionCategories: TObjectList<TOptionCategoriesDTO>;
   FOptionPrice: Integer;
   FPrice: Integer;
   FPriceWithOption: Integer;
   FProduct: string;
   FTotalOptionPrice: Integer;
   FTotalPrice: Integer;
   FTotalPriceWithOption: Integer;
   FWideImageURL: string;
   function GetOptionCategories: TObjectList<TOptionCategoriesDTO>;
 published
   property ChainProduct: string read FChainProduct write FChainProduct;
   property Count: Integer read FCount write FCount;
   property DisplayInfo: TDisplayInfoDTO read FDisplayInfo write FDisplayInfo;
   property Id: string read FId write FId;
   property ImageURL: string read FImageURL write FImageURL;
   property Name: TNameDTO read FName write FName;
   property OptionCategories: TObjectList<TOptionCategoriesDTO> read GetOptionCategories;
   property OptionPrice: Integer read FOptionPrice write FOptionPrice;
   property Price: Integer read FPrice write FPrice;
   property PriceWithOption: Integer read FPriceWithOption write FPriceWithOption;
   property Product: string read FProduct write FProduct;
   property TotalOptionPrice: Integer read FTotalOptionPrice write FTotalOptionPrice;
   property TotalPrice: Integer read FTotalPrice write FTotalPrice;
   property TotalPriceWithOption: Integer read FTotalPriceWithOption write FTotalPriceWithOption;
   property WideImageURL: string read FWideImageURL write FWideImageURL;
 public
   constructor Create;
   destructor Destroy; override;
 end;
 
 TLocationDTO_001 = class
 private
   FLat: Double;
   FLon: Double;
 published
   property Lat: Double read FLat write FLat;
   property Lon: Double read FLon write FLon;
 end;
 
 TCourierDTO = class
 private
   FId: string;
   FLocation: TLocationDTO_001;
   FName: string;
   FStatus: Integer;
 published
   property Id: string read FId write FId;
   property Location: TLocationDTO_001 read FLocation write FLocation;
   property Name: string read FName write FName;
   property Status: Integer read FStatus write FStatus;
 public
   constructor Create;
   destructor Destroy; override;
 end;
 
 TDeliveryAddressDTO = class
 private
   FAddress: string;
   FAptNo: string;
   FDescription: string;
   FDoorNo: string;
   FFloor: string;
   FId: string;
 published
   property Address: string read FAddress write FAddress;
   property AptNo: string read FAptNo write FAptNo;
   property Description: string read FDescription write FDescription;
   property DoorNo: string read FDoorNo write FDoorNo;
   property Floor: string read FFloor write FFloor;
   property Id: string read FId write FId;
 end;
 
 TLocationDTO = class
 private
   FLat: Double;
   FLon: Double;
 published
   property Lat: Double read FLat write FLat;
   property Lon: Double read FLon write FLon;
 end;
 
 TClientDTO = class
 private
   FClientPhoneNumber: string;
   FContactPhoneNumber: string;
   FDeliveryAddress: TDeliveryAddressDTO;
   FId: string;
   FLocation: TLocationDTO;
   FName: string;
 published
   property ClientPhoneNumber: string read FClientPhoneNumber write FClientPhoneNumber;
   property ContactPhoneNumber: string read FContactPhoneNumber write FContactPhoneNumber;
   property DeliveryAddress: TDeliveryAddressDTO read FDeliveryAddress write FDeliveryAddress;
   property Id: string read FId write FId;
   property Location: TLocationDTO read FLocation write FLocation;
   property Name: string read FName write FName;
 public
   constructor Create;
   destructor Destroy; override;
 end;
 
 TItemDTO = class
 private
   FCheckoutDate: TDateTime;
   FClient: TClientDTO;
   FClientNote: string;
   FConfirmationId: string;
   FCourier: TCourierDTO;
   FDeliveryType: Integer;
   FDoNotKnock: Boolean;
   FId: string;
   FIsEcoFriendly: Boolean;
   FIsScheduled: Boolean;
   FPaymentMethod: Integer;
   FPaymentMethodText: TPaymentMethodTextDTO;
   [JSONName('products')]
   FProductsArray: TArray<TProductsDTO>;
   [GenericListReflect]
   FProducts: TObjectList<TProductsDTO>;
   FRestaurant: TRestaurantDTO;
   FStatus: Integer;
   FTotalPrice: Integer;
   function GetProducts: TObjectList<TProductsDTO>;
 published
   property CheckoutDate: TDateTime read FCheckoutDate write FCheckoutDate;
   property Client: TClientDTO read FClient write FClient;
   property ClientNote: string read FClientNote write FClientNote;
   property ConfirmationId: string read FConfirmationId write FConfirmationId;
   property Courier: TCourierDTO read FCourier write FCourier;
   property DeliveryType: Integer read FDeliveryType write FDeliveryType;
   property DoNotKnock: Boolean read FDoNotKnock write FDoNotKnock;
   property Id: string read FId write FId;
   property IsEcoFriendly: Boolean read FIsEcoFriendly write FIsEcoFriendly;
   property IsScheduled: Boolean read FIsScheduled write FIsScheduled;
   property PaymentMethod: Integer read FPaymentMethod write FPaymentMethod;
   property PaymentMethodText: TPaymentMethodTextDTO read FPaymentMethodText write FPaymentMethodText;
   property Products: TObjectList<TProductsDTO> read GetProducts;
   property Restaurant: TRestaurantDTO read FRestaurant write FRestaurant;
   property Status: Integer read FStatus write FStatus;
   property TotalPrice: Integer read FTotalPrice write FTotalPrice;
 public
   constructor Create;
   destructor Destroy; override;
 end;
 
 TRootDTO = class(TJsonDTO)
 private
   [JSONName('Items')]
   FItemsArray: TArray<TItemDTO>;
   [GenericListReflect]
   FItems: TObjectList<TItemDTO>;
   function GetItems: TObjectList<TItemDTO>;
 published
   property Items: TObjectList<TItemDTO> read GetItems;
   destructor Destroy; override;
 end;
 
implementation

{ TOptionsDTO }

destructor TOptionsDTO.Destroy;
begin
 GetTr.Free;
 GetEn.Free;
 inherited;
end;

function TOptionsDTO.GetTr: TObjectList<TTrDTO>;
begin
 if not Assigned(FTr) then
 begin
   FTr := TObjectList<TTrDTO>.Create;
   FTr.AddRange(FTrArray);
 end;
 Result := FTr;
end;

function TOptionsDTO.GetEn: TObjectList<TEnDTO>;
begin
 if not Assigned(FEn) then
 begin
   FEn := TObjectList<TEnDTO>.Create;
   FEn.AddRange(FEnArray);
 end;
 Result := FEn;
end;

{ TDisplayInfoDTO }

constructor TDisplayInfoDTO.Create;
begin
 inherited;
 FTitle := TTitleDTO.Create;
 FOptions := TOptionsDTO.Create;
end;

destructor TDisplayInfoDTO.Destroy;
begin
 FTitle.Free;
 FOptions.Free;
 inherited;
end;

{ TProductsDTO }

constructor TProductsDTO.Create;
begin
 inherited;
 FName := TNameDTO.Create;
 FDisplayInfo := TDisplayInfoDTO.Create;
end;

destructor TProductsDTO.Destroy;
begin
 FName.Free;
 FDisplayInfo.Free;
 GetOptionCategories.Free;
 inherited;
end;

function TProductsDTO.GetOptionCategories: TObjectList<TOptionCategoriesDTO>;
begin
 if not Assigned(FOptionCategories) then
 begin
   FOptionCategories := TObjectList<TOptionCategoriesDTO>.Create;
   FOptionCategories.AddRange(FOptionCategoriesArray);
 end;
 Result := FOptionCategories;
end;

{ TCourierDTO }

constructor TCourierDTO.Create;
begin
 inherited;
 FLocation := TLocationDTO_001.Create;
end;

destructor TCourierDTO.Destroy;
begin
 FLocation.Free;
 inherited;
end;

{ TClientDTO }

constructor TClientDTO.Create;
begin
 inherited;
 FLocation := TLocationDTO.Create;
 FDeliveryAddress := TDeliveryAddressDTO.Create;
end;

destructor TClientDTO.Destroy;
begin
 FLocation.Free;
 FDeliveryAddress.Free;
 inherited;
end;

{ TItemDTO }

constructor TItemDTO.Create;
begin
 inherited;
 FClient := TClientDTO.Create;
 FCourier := TCourierDTO.Create;
 FRestaurant := TRestaurantDTO.Create;
 FPaymentMethodText := TPaymentMethodTextDTO.Create;
end;

destructor TItemDTO.Destroy;
begin
 FClient.Free;
 FCourier.Free;
 FRestaurant.Free;
 FPaymentMethodText.Free;
 GetProducts.Free;
 inherited;
end;

function TItemDTO.GetProducts: TObjectList<TProductsDTO>;
begin
 if not Assigned(FProducts) then
 begin
   FProducts := TObjectList<TProductsDTO>.Create;
   FProducts.AddRange(FProductsArray);
 end;
 Result := FProducts;
end;

{ TRootDTO }

destructor TRootDTO.Destroy;
begin
 GetItems.Free;
 inherited;
end;

function TRootDTO.GetItems: TObjectList<TItemDTO>;
begin
 if not Assigned(FItems) then
 begin
   FItems := TObjectList<TItemDTO>.Create;
   FItems.AddRange(FItemsArray);
 end;
 Result := FItems;
end;

end.
Cevapla


Bu Konudaki Yorumlar
json parse - Yazar: PİRSUS23 - 11-10-2018, Saat: 15:06
json parse - Yazar: SimaWB - 11-10-2018, Saat: 15:39
Cvp: json parse - Yazar: TescilsizUzman - 11-10-2018, Saat: 16:00
json parse - Yazar: PİRSUS23 - 11-10-2018, Saat: 16:05
json parse - Yazar: Tuğrul HELVACI - 11-10-2018, Saat: 16:15
json parse - Yazar: edo - 11-10-2018, Saat: 17:55
Cvp: json parse - Yazar: TescilsizUzman - 11-10-2018, Saat: 18:47
json parse - Yazar: PİRSUS23 - 12-10-2018, Saat: 09:23
Cvp: json parse - Yazar: ozcanm - 12-10-2018, Saat: 14:12
json parse - Yazar: arsl01 - 12-10-2018, Saat: 15:03
Cvp: json parse - Yazar: TescilsizUzman - 12-10-2018, Saat: 17:17
json parse - Yazar: yhackup - 13-10-2018, Saat: 16:50
Cvp: json parse - Yazar: TescilsizUzman - 13-10-2018, Saat: 17:55
Cvp: json parse - Yazar: Halil Han BADEM - 14-10-2018, Saat: 01:57
Cvp: json parse - Yazar: tmrksmt - 08-01-2021, Saat: 04:22
Cvp: json parse - Yazar: RAD Coder - 08-01-2021, Saat: 10:01
Cvp: json parse - Yazar: tmrksmt - 08-01-2021, Saat: 12:03

Konu ile Alakalı Benzer Konular
Konular Yazar Yorumlar Okunma Son Yorum
  JSON DataSet Serialize for Unidac Halil Han BADEM 2 516 08-11-2023, Saat: 16:53
Son Yorum: Halil Han BADEM
  JSON Verilerini Veritabanına Kaydetmek kajmerantime 6 756 03-11-2023, Saat: 15:05
Son Yorum: kajmerantime
  JSon Format m_ekici 7 951 02-10-2023, Saat: 09:24
Son Yorum: yhackup
  RESTRequest Nesnesinde Body içinde JSON Gönderme Hk. pro_imaj 2 606 04-06-2023, Saat: 00:47
Son Yorum: pro_imaj
Exclamation delphi json binance uygulaması yardım fix1tr 7 1.642 31-03-2023, Saat: 10:48
Son Yorum: fix1tr



Konuyu Okuyanlar: 1 Ziyaretçi