2016-06-02 6 views
-3

저는 Delphi 10 Seattle으로 애플리케이션을 개발 중입니다.json 응답에서 데이터 읽기

JSON에서 항목 값을 읽으려고합니다. 예를 들어

는 :

{ 
    "findCompletedItemsResponse":[ 
    { 
     "ack":[ 
     "Success" 
     ], 
     "version":[ 
     "1.13.0" 
     ], 
     "timestamp":[ 
     "2016-06-02T16:07:36.736Z" 
     ], 
     "searchResult":[ 
     { 
      "@count":"2", 
      "item":[ 
      { 
       "itemId":[ 
       "172168793372" 
       ], 
       "title":[ 
       "Nikon D5000 12.3 MP Digital SLR Camera (Body Only with Accessories)" 
       ], 
       "globalId":[ 
       "EBAY-US" 
       ], 
       "primaryCategory":[ 
       { 
        "categoryId":[ 
        "31388" 
        ], 
        "categoryName":[ 
        "Digital Cameras" 
        ] 
       } 
       ], 
       "galleryURL":[ 
       "http:\/\/thumbs1.ebaystatic.com\/m\/mlRCNAriHPzowbSV9Q7ZFAg\/140.jpg" 
       ], 
       "viewItemURL":[ 
       "http:\/\/www.ebay.com\/itm\/Nikon-D5000-12-3-MP-Digital-SLR-Camera-Body-Only-Accessories-\/172168793372" 
       ], 
       "paymentMethod":[ 
       "PayPal" 
       ], 
       "autoPay":[ 
       "false" 
       ], 
       "postalCode":[ 
       "02806" 
       ], 
       "location":[ 
       "Barrington,RI,USA" 
       ], 
       "country":[ 
       "US" 
       ], 
       "shippingInfo":[ 
       { 
        "shippingServiceCost":[ 
        { 
         "@currencyId":"USD", 
         "__value__":"0.0" 
        } 
        ], 
        "shippingType":[ 
        "Free" 
        ], 
        "shipToLocations":[ 
        "US" 
        ], 
        "expeditedShipping":[ 
        "true" 
        ], 
        "oneDayShippingAvailable":[ 
        "false" 
        ], 
        "handlingTime":[ 
        "2" 
        ] 
       } 
       ], 
       "sellingStatus":[ 
       { 
        "currentPrice":[ 
        { 
         "@currencyId":"USD", 
         "__value__":"178.5" 
        } 
        ], 
        "convertedCurrentPrice":[ 
        { 
         "@currencyId":"USD", 
         "__value__":"178.5" 
        } 
        ], 
        "bidCount":[ 
        "13" 
        ], 
        "sellingState":[ 
        "EndedWithSales" 
        ] 
       } 
       ], 
       "listingInfo":[ 
       { 
        "bestOfferEnabled":[ 
        "false" 
        ], 
        "buyItNowAvailable":[ 
        "false" 
        ], 
        "startTime":[ 
        "2016-04-18T18:45:54.000Z" 
        ], 
        "endTime":[ 
        "2016-04-25T18:45:54.000Z" 
        ], 
        "listingType":[ 
        "Auction" 
        ], 
        "gift":[ 
        "false" 
        ] 
       } 
       ], 
       "returnsAccepted":[ 
       "false" 
       ], 
       "condition":[ 
       { 
        "conditionId":[ 
        "3000" 
        ], 
        "conditionDisplayName":[ 
        "Used" 
        ] 
       } 
       ], 
       "isMultiVariationListing":[ 
       "false" 
       ], 
       "topRatedListing":[ 
       "false" 
       ] 
      }, 
      { 
       "itemId":[ 
       "172200026135" 
       ], 
       "title":[ 
       "Nikon D5000 12.3 MP Digital SLR Camera (Body Only with Accessories)" 
       ], 
       "globalId":[ 
       "EBAY-US" 
       ], 
       "primaryCategory":[ 
       { 
        "categoryId":[ 
        "31388" 
        ], 
        "categoryName":[ 
        "Digital Cameras" 
        ] 
       } 
       ], 
       "galleryURL":[ 
       "http:\/\/thumbs4.ebaystatic.com\/m\/mlRCNAriHPzowbSV9Q7ZFAg\/140.jpg" 
       ], 
       "viewItemURL":[ 
       "http:\/\/www.ebay.com\/itm\/Nikon-D5000-12-3-MP-Digital-SLR-Camera-Body-Only-Accessories-\/172200026135" 
       ], 
       "paymentMethod":[ 
       "PayPal" 
       ], 
       "autoPay":[ 
       "false" 
       ], 
       "postalCode":[ 
       "02806" 
       ], 
       "location":[ 
       "Barrington,RI,USA" 
       ], 
       "country":[ 
       "US" 
       ], 
       "shippingInfo":[ 
       { 
        "shippingServiceCost":[ 
        { 
         "@currencyId":"USD", 
         "__value__":"0.0" 
        } 
        ], 
        "shippingType":[ 
        "Free" 
        ], 
        "shipToLocations":[ 
        "US" 
        ], 
        "expeditedShipping":[ 
        "true" 
        ], 
        "oneDayShippingAvailable":[ 
        "false" 
        ], 
        "handlingTime":[ 
        "2" 
        ] 
       } 
       ], 
       "sellingStatus":[ 
       { 
        "currentPrice":[ 
        { 
         "@currencyId":"USD", 
         "__value__":"119.49" 
        } 
        ], 
        "convertedCurrentPrice":[ 
        { 
         "@currencyId":"USD", 
         "__value__":"119.49" 
        } 
        ], 
        "bidCount":[ 
        "2" 
        ], 
        "sellingState":[ 
        "EndedWithSales" 
        ] 
       } 
       ], 
       "listingInfo":[ 
       { 
        "bestOfferEnabled":[ 
        "false" 
        ], 
        "buyItNowAvailable":[ 
        "false" 
        ], 
        "startTime":[ 
        "2016-05-10T07:22:34.000Z" 
        ], 
        "endTime":[ 
        "2016-05-16T19:22:25.000Z" 
        ], 
        "listingType":[ 
        "Auction" 
        ], 
        "gift":[ 
        "false" 
        ] 
       } 
       ], 
       "returnsAccepted":[ 
       "false" 
       ], 
       "condition":[ 
       { 
        "conditionId":[ 
        "3000" 
        ], 
        "conditionDisplayName":[ 
        "Used" 
        ] 
       } 
       ], 
       "isMultiVariationListing":[ 
       "false" 
       ], 
       "topRatedListing":[ 
       "false" 
       ] 
      } 
      ] 
     } 
     ], 
     "paginationOutput":[ 
     { 
      "pageNumber":[ 
      "1" 
      ], 
      "entriesPerPage":[ 
      "100" 
      ], 
      "totalPages":[ 
      "1" 
      ], 
      "totalEntries":[ 
      "2" 
      ] 
     } 
     ] 
    } 
    ] 
} 

난 단지 이베이에 나열된 항목의 가격을 추출 할. 나는 currentPrice을 추측한다.

어떻게 변수의 가격 만 추출 할 수 있습니까?

+0

당신의 JSON 문자열을하시기 바랍니다 포맷 할 수 있습니까? –

+0

이 JSON 문자열을 완성하십시오. –

+0

많은 리소스가 있으므로 여기에서 많은 리소스를 참조하십시오. 아직 시도해 보셨습니까? –

답변

4

이것은 끔찍한 JSON입니다. 이 데이터를 설계 한 사람은 JSON을 전혀 이해하지 못합니다. 이 JSON은 1 요소 배열과 문자열 값을 많이 남용합니다. 대부분의 배열은 전혀 속하지 않으며 JSON에는 사용할 수있는 다른 데이터 유형 (부울, 정수 등)이 있습니다. 어떤 경우

, 당신이 사용할 수있는 델파이의 내장 JSON framework이 JSON을 구문 분석, 예를 들면 :

uses 
    System.JSON; 

var 
    json: string; 
    obj: TJSONObject; 
    completedItems, sresults, items, status, price: TJSONArray; 
    I, J, K: Integer; 
    currencyId, value: string; 
begin 
    json := ...; // <-- your JSON string here 
    obj := TJSONObject.ParseJSONValue(json, 0) as TJSONObject; 
    try 
    completedItems := obj.Values['findCompletedItemsResponse'] as TJSONArray; 
    for I := 0 to completedItems.Count-1 do 
    begin 
     sresults := (completedItems.Items[I] as TJSONObject).Values['searchResult'] as TJSONArray; 
     for J := 0 to sresults.Count-1 do 
     begin 
     items := (sresults.Items[J] as TJSONObject).Values['item'] as TJSONArray; 
     for K := 0 to items.Count-1 do 
     begin 
      status := (items.Items[K] as TJSONObject).Values['sellingStatus'] as TJSONArray; 
      price := ((status.Items[0] as TJSONObject).Values['currentPrice']) as TJSONArray; 
      currencyId := price.Values['@currencyId'].Value; 
      value := price.Values['__value__'].Value; 
      // use price values as needed... 
     end; 
     end; 
    finally 
     obj.Free; 
    end; 
    end; 

또는 :

uses 
    System.JSON, System.JSON.Types; 

var 
    json: string; 
    sreader: TStringReader; 
    jreader: TJsonTextReader; 
    inCurrentPrice: Boolean; 
    currencyId, value: string; 
begin 
    json := ...; // <-- your JSON string here 
    sreader := TStringReader.Create(json); 
    try 
    jreader := TJsonTextReader.Create(sreader); 
    try 
     inCurrentPrice := False; 
     while jreader.Read do 
     begin 
     case jreader.TokenType of 
      TJsonToken.PropertyName: begin 
      if inCurrentPrice then 
      begin 
       if jreader.Value.AsString = 'currencyId' then begin 
       currencyId := jreader.ReadAsString; 
       end 
       else if jreader.Value.AsString = '__value__' then begin 
       value := jreader.ReadAsString; 
       end; 
      end 
      else if jreader.Value.AsString = 'currentPrice' then 
      begin 
       currencyId := ''; 
       value := ''; 
       inCurrentPrice := True; 
      end; 
      end; 
      TJsonToken.EndArray: begin 
      if inCurrentPrice then 
      begin 
       inCurrentPrice := False; 
       // use currency values as needed... 
      end; 
      end; 
     end; 
     end; 
    finally 
     jreader.Free; 
    end; 
    finally 
    sreader.Free; 
    end; 
end; 
+0

유용한 답변을 보내 주셔서 감사합니다. 하지만 위의 코드를 data.json에 속해야합니까?또는 제 경우에는 TMemo에서 json 응답을 받았습니다. TMemo에 코드를 포함시켜야합니까? 그리고 어떻게해야합니까? (내가 게시 한 두 번째 코드 스 니펫을 사용하고 있습니다.) –

+0

@LiamBonactarian : 내가 무엇을 묻고 있는지 이해할 수 없습니다. 하지만 파서가 처리 할 문자열을 얻을 수있는 한 JSON 데이터를 어디서 가져올 지 중요하지 않습니다. (그리고 TIdHTTP.Get()는'string'을 반환 할 수 있으므로, 먼저 'TMemo'에 넣어야합니다.) –

+0

아 좋아! 위 예제에서 json 요청을 문자열 (json : string)에 저장 했습니까? –

2

이와 같은 도구를 사용하여이 JSON에 대한 봉투를 생성 할 수 있습니다.

http://www.pgeorgiev.com/?p=1832

코드는 다음과 같습니다

unit Test1; 

// ************************************************* 
// Generated By: JsonToDelphiClass - 0.65 
// Project link: https://github.com/PKGeorgiev/Delphi-JsonToDelphiClass 
// Generated On: 2016-06-02 17:46:09 
// ************************************************* 
// Created By : Petar Georgiev - 2014 
// WebSite  : http://pgeorgiev.com 
// ************************************************* 

interface 

uses Generics.Collections, Rest.Json; 

type 

TConditionClass = class 
private 
    FConditionDisplayName: TArray<String>; 
    FConditionId: TArray<String>; 
public 
    property conditionDisplayName: TArray<String> read FConditionDisplayName write FConditionDisplayName; 
    property conditionId: TArray<String> read FConditionId write FConditionId; 
    function ToJsonString: string; 
    class function FromJsonString(AJsonString: string): TConditionClass; 
end; 

TListingInfoClass = class 
private 
    FBestOfferEnabled: TArray<String>; 
    FBuyItNowAvailable: TArray<String>; 
    FEndTime: TArray<String>; 
    FGift: TArray<String>; 
    FListingType: TArray<String>; 
    FStartTime: TArray<String>; 
public 
    property bestOfferEnabled: TArray<String> read FBestOfferEnabled write FBestOfferEnabled; 
    property buyItNowAvailable: TArray<String> read FBuyItNowAvailable write FBuyItNowAvailable; 
    property endTime: TArray<String> read FEndTime write FEndTime; 
    property gift: TArray<String> read FGift write FGift; 
    property listingType: TArray<String> read FListingType write FListingType; 
    property startTime: TArray<String> read FStartTime write FStartTime; 
    function ToJsonString: string; 
    class function FromJsonString(AJsonString: string): TListingInfoClass; 
end; 

TConvertedCurrentPriceClass = class 
private 
    FAcurrencyId: String; 
    F__value__: String; 
public 
    property AcurrencyId: String read FAcurrencyId write FAcurrencyId; 
    property __value__: String read F__value__ write F__value__; 
    function ToJsonString: string; 
    class function FromJsonString(AJsonString: string): TConvertedCurrentPriceClass; 
end; 

TCurrentPriceClass = class 
private 
    FAcurrencyId: String; 
    F__value__: String; 
public 
    property AcurrencyId: String read FAcurrencyId write FAcurrencyId; 
    property __value__: String read F__value__ write F__value__; 
    function ToJsonString: string; 
    class function FromJsonString(AJsonString: string): TCurrentPriceClass; 
end; 

TSellingStatusClass = class 
private 
    FBidCount: TArray<String>; 
    FConvertedCurrentPrice: TArray<TConvertedCurrentPriceClass>; 
    FCurrentPrice: TArray<TCurrentPriceClass>; 
    FSellingState: TArray<String>; 
public 
    property bidCount: TArray<String> read FBidCount write FBidCount; 
    property convertedCurrentPrice: TArray<TConvertedCurrentPriceClass> read FConvertedCurrentPrice write FConvertedCurrentPrice; 
    property currentPrice: TArray<TCurrentPriceClass> read FCurrentPrice write FCurrentPrice; 
    property sellingState: TArray<String> read FSellingState write FSellingState; 
    destructor Destroy; override; 
    function ToJsonString: string; 
    class function FromJsonString(AJsonString: string): TSellingStatusClass; 
end; 

TShippingInfoClass = class 
private 
    FExpeditedShipping: TArray<String>; 
    FHandlingTime: TArray<String>; 
    FOneDayShippingAvailable: TArray<String>; 
    FShipToLocations: TArray<String>; 
    FShippingType: TArray<String>; 
public 
    property expeditedShipping: TArray<String> read FExpeditedShipping write FExpeditedShipping; 
    property handlingTime: TArray<String> read FHandlingTime write FHandlingTime; 
    property oneDayShippingAvailable: TArray<String> read FOneDayShippingAvailable write FOneDayShippingAvailable; 
    property shipToLocations: TArray<String> read FShipToLocations write FShipToLocations; 
    property shippingType: TArray<String> read FShippingType write FShippingType; 
    function ToJsonString: string; 
    class function FromJsonString(AJsonString: string): TShippingInfoClass; 
end; 

TProductIdClass = class 
private 
    FAtype: String; 
    F__value__: String; 
public 
    property Atype: String read FAtype write FAtype; 
    property __value__: String read F__value__ write F__value__; 
    function ToJsonString: string; 
    class function FromJsonString(AJsonString: string): TProductIdClass; 
end; 

TPrimaryCategoryClass = class 
private 
    FCategoryId: TArray<String>; 
    FCategoryName: TArray<String>; 
public 
    property categoryId: TArray<String> read FCategoryId write FCategoryId; 
    property categoryName: TArray<String> read FCategoryName write FCategoryName; 
    function ToJsonString: string; 
    class function FromJsonString(AJsonString: string): TPrimaryCategoryClass; 
end; 

TItemClass = class 
private 
    FAutoPay: TArray<String>; 
    FCondition: TArray<TConditionClass>; 
    FCountry: TArray<String>; 
    FGalleryURL: TArray<String>; 
    FGlobalId: TArray<String>; 
    FIsMultiVariationListing: TArray<String>; 
    FItemId: TArray<String>; 
    FListingInfo: TArray<TListingInfoClass>; 
    FLocation: TArray<String>; 
    FPaymentMethod: TArray<String>; 
    FPostalCode: TArray<String>; 
    FPrimaryCategory: TArray<TPrimaryCategoryClass>; 
    FProductId: TArray<TProductIdClass>; 
    FReturnsAccepted: TArray<String>; 
    FSellingStatus: TArray<TSellingStatusClass>; 
    FShippingInfo: TArray<TShippingInfoClass>; 
    FTitle: TArray<String>; 
    FTopRatedListing: TArray<String>; 
    FViewItemURL: TArray<String>; 
public 
    property autoPay: TArray<String> read FAutoPay write FAutoPay; 
    property condition: TArray<TConditionClass> read FCondition write FCondition; 
    property country: TArray<String> read FCountry write FCountry; 
    property galleryURL: TArray<String> read FGalleryURL write FGalleryURL; 
    property globalId: TArray<String> read FGlobalId write FGlobalId; 
    property isMultiVariationListing: TArray<String> read FIsMultiVariationListing write FIsMultiVariationListing; 
    property itemId: TArray<String> read FItemId write FItemId; 
    property listingInfo: TArray<TListingInfoClass> read FListingInfo write FListingInfo; 
    property location: TArray<String> read FLocation write FLocation; 
    property paymentMethod: TArray<String> read FPaymentMethod write FPaymentMethod; 
    property postalCode: TArray<String> read FPostalCode write FPostalCode; 
    property primaryCategory: TArray<TPrimaryCategoryClass> read FPrimaryCategory write FPrimaryCategory; 
    property productId: TArray<TProductIdClass> read FProductId write FProductId; 
    property returnsAccepted: TArray<String> read FReturnsAccepted write FReturnsAccepted; 
    property sellingStatus: TArray<TSellingStatusClass> read FSellingStatus write FSellingStatus; 
    property shippingInfo: TArray<TShippingInfoClass> read FShippingInfo write FShippingInfo; 
    property title: TArray<String> read FTitle write FTitle; 
    property topRatedListing: TArray<String> read FTopRatedListing write FTopRatedListing; 
    property viewItemURL: TArray<String> read FViewItemURL write FViewItemURL; 
    destructor Destroy; override; 
    function ToJsonString: string; 
    class function FromJsonString(AJsonString: string): TItemClass; 
end; 

TSearchResultClass = class 
private 
    FAcount: String; 
    FItem: TArray<TItemClass>; 
public 
    property Acount: String read FAcount write FAcount; 
    property item: TArray<TItemClass> read FItem write FItem; 
    destructor Destroy; override; 
    function ToJsonString: string; 
    class function FromJsonString(AJsonString: string): TSearchResultClass; 
end; 

TFindCompletedItemsResponseClass = class 
private 
    FAck: TArray<String>; 
    FSearchResult: TArray<TSearchResultClass>; 
    FTimestamp: TArray<String>; 
    FVersion: TArray<String>; 
public 
    property ack: TArray<String> read FAck write FAck; 
    property searchResult: TArray<TSearchResultClass> read FSearchResult write FSearchResult; 
    property timestamp: TArray<String> read FTimestamp write FTimestamp; 
    property version: TArray<String> read FVersion write FVersion; 
    destructor Destroy; override; 
    function ToJsonString: string; 
    class function FromJsonString(AJsonString: string): TFindCompletedItemsResponseClass; 
end; 

TRootClass = class 
private 
    FFindCompletedItemsResponse: TArray<TFindCompletedItemsResponseClass>; 
public 
    property findCompletedItemsResponse: TArray<TFindCompletedItemsResponseClass> read FFindCompletedItemsResponse write FFindCompletedItemsResponse; 
    destructor Destroy; override; 
    function ToJsonString: string; 
    class function FromJsonString(AJsonString: string): TRootClass; 
end; 

implementation 

{TConditionClass} 


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

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

{TListingInfoClass} 


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

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

{TConvertedCurrentPriceClass} 


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

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

{TCurrentPriceClass} 


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

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

{TSellingStatusClass} 

destructor TSellingStatusClass.Destroy; 
var 
    LcurrentPriceItem: TCurrentPriceClass; 
    LconvertedCurrentPriceItem: TConvertedCurrentPriceClass; 
begin 

for LcurrentPriceItem in FCurrentPrice do 
    LcurrentPriceItem.free; 
for LconvertedCurrentPriceItem in FConvertedCurrentPrice do 
    LconvertedCurrentPriceItem.free; 

    inherited; 
end; 

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

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

{TShippingInfoClass} 


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

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

{TProductIdClass} 


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

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

{TPrimaryCategoryClass} 


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

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

{TItemClass} 

destructor TItemClass.Destroy; 
var 
    LprimaryCategoryItem: TPrimaryCategoryClass; 
    LproductIdItem: TProductIdClass; 
    LshippingInfoItem: TShippingInfoClass; 
    LsellingStatusItem: TSellingStatusClass; 
    LlistingInfoItem: TListingInfoClass; 
    LconditionItem: TConditionClass; 
begin 

for LprimaryCategoryItem in FPrimaryCategory do 
    LprimaryCategoryItem.free; 
for LproductIdItem in FProductId do 
    LproductIdItem.free; 
for LshippingInfoItem in FShippingInfo do 
    LshippingInfoItem.free; 
for LsellingStatusItem in FSellingStatus do 
    LsellingStatusItem.free; 
for LlistingInfoItem in FListingInfo do 
    LlistingInfoItem.free; 
for LconditionItem in FCondition do 
    LconditionItem.free; 

    inherited; 
end; 

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

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

{TSearchResultClass} 

destructor TSearchResultClass.Destroy; 
var 
    LitemItem: TItemClass; 
begin 

for LitemItem in FItem do 
    LitemItem.free; 

    inherited; 
end; 

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

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

{TFindCompletedItemsResponseClass} 

destructor TFindCompletedItemsResponseClass.Destroy; 
var 
    LsearchResultItem: TSearchResultClass; 
begin 

for LsearchResultItem in FSearchResult do 
    LsearchResultItem.free; 

    inherited; 
end; 

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

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

{TRootClass} 

destructor TRootClass.Destroy; 
var 
    LfindCompletedItemsResponseItem: TFindCompletedItemsResponseClass; 
begin 

for LfindCompletedItemsResponseItem in FFindCompletedItemsResponse do 
    LfindCompletedItemsResponseItem.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. 

당신이 그것을 일단, 다음과 유사한 코드는 당신이 필요로하는 가치를 얻을 수 있습니다.

procedure TForm1.Button1Click(Sender: TObject); 
var 
    cr:TRootClass; 
    rc:TFindCompletedItemsResponseClass; 
    sr:TSearchResultClass; 
    it:TItemClass; 
    ss:TSellingStatusClass; 
    cp:TCurrentPriceClass; 
    str:string; 
begin 
    cr := TRootClass.FromJsonString(Memo1.Lines.Text); 
    rc := cr.findCompletedItemsResponse[0]; 
    sr := rc.searchResult[0]; 
    it := sr.item[0]; 
    ss := it.sellingStatus[0]; 
    cp := ss.currentPrice[0]; 
    // current price 
    Str := cp.__value__;  <<======= 
end; 

감사합니다.

PD : 더 나은 답변을 얻으려면 더 나은 질문을 수행하는 데 오래 걸리십시오.