2016-06-08 3 views
-2

저는 아래의 json 코드에서 totalentries (json의 끝에서) 값을 얻으려고 실제로합니다 (idhttp.get의 응답은 ebay API 찾기 호출에서 온 것입니다). 나는 실제로 이것을 이렇게 시험하고있다 : 아무도 나를 도울 수 있 었는가? 이 중델파이 json의 값을 읽으십시오.

procedure TForm2.Button1Click(Sender: TObject); 
var 
jsonreader: TStringReader; 
jsontextreader: TJsonTextReader; 
totalentries: string; 
totalentries2: Boolean ; 
js: string; 
value2: string; 
begin 
js := IdHTTP1.Get('http://svcs.ebay.com/services/search/FindingService/v1?OPERATION-NAME=findItemsByKeywords&SERVICE-VERSION=1.0.0&SECURITY-APPNAME=MyAppIdishere&RESPONSE-DATA-FORMAT=JSON&REST-PAYLOAD&keywords=Mac%20Mini%202.4ghz%208gb%20ram'); 
jsonreader := TStringReader.Create(js); 
try 
jsontextreader := TJsonTextReader.Create(jsonreader); 
try 
    totalentries2 := False; 
    while jsontextreader.Read do 
    begin 
    case jsontextreader.TokenType of 
     TJsonToken.PropertyName: begin 
     if totalentries2 then 
     begin 
      if jsontextreader.Value.AsString = 'totalEntries' then begin 
      value2 := jsontextreader.ReadAsString; 
     end 
     else if jsontextreader.Value.AsString = 'paginationOutput' then 
     begin 
      totalentries := ''; 
      value2 := ''; 
      totalentries2 := True; 
     end; 
     end; 
     end; 
     TJsonToken.EndArray: begin 
     if totalentries2 then 
     begin 
      totalentries2 := False; 
      ShowMessage(value2); 
     end; 
     end; 
    end; 
    end; 
finally 
    jsontextreader.Free; 
end; 
finally 
jsonreader.Free; 
end; 
end; 

이 같은

{ 
"findItemsByKeywordsResponse":[ 
{ 
    "ack":[ 
    "Success" 
    ], 
    "version":[ 
    "1.13.0" 
    ], 
    "timestamp":[ 
    "2016-06-09T19:28:07.144Z" 
    ], 
    "searchResult":[ 
    { 
     "@count":"13", 
     "item":[ 
     { 
      "itemId":[ 
      "191821047016" 
      ], 
      "title":[ 
      "8GB PC3-8500S DDR3-1066Mhz Memory Mac mini (Mid 2010), Mini4,1 2.4Ghz 2.66Ghz" 
      ], 
      "globalId":[ 
      "EBAY-US" 
      ], 
      "primaryCategory":[ 
      { 
       "categoryId":[ 
       "170083" 
       ], 
       "categoryName":[ 
       "Memory (RAM)" 
       ] 
      } 
      ], 
      "galleryURL":[ 
      "http:\/\/thumbs1.ebaystatic.com\/m\/mg8ULWhHnLALUsr6XsX20hQ\/140.jpg" 
      ], 
      "viewItemURL":[ 
      "http:\/\/www.ebay.com\/itm\/8GB-PC3-8500S-DDR3-1066Mhz-Memory-Mac-mini-Mid-2010-Mini4-1-2-4Ghz-2-66Ghz-\/191821047016" 
      ], 
      "paymentMethod":[ 
      "PayPal" 
      ], 
      "autoPay":[ 
      "false" 
      ], 
      "postalCode":[ 
      "95054" 
      ], 
      "location":[ 
      "Santa Clara,CA,USA" 
      ], 
      "country":[ 
      "US" 
      ], 
      "shippingInfo":[ 
      { 
       "shippingServiceCost":[ 
       { 
        "@currencyId":"USD", 
        "__value__":"0.0" 
       } 
       ], 
       "shippingType":[ 
       "Free" 
       ], 
       "shipToLocations":[ 
       "Worldwide" 
       ], 
       "expeditedShipping":[ 
       "true" 
       ], 
       "oneDayShippingAvailable":[ 
       "false" 
       ], 
       "handlingTime":[ 
       "1" 
       ] 
      } 
      ], 
      "sellingStatus":[ 
      { 
       "currentPrice":[ 
       { 
        "@currencyId":"USD", 
        "__value__":"31.95" 
       } 
       ], 
       "convertedCurrentPrice":[ 
       { 
        "@currencyId":"USD", 
        "__value__":"31.95" 
       } 
       ], 
       "sellingState":[ 
       "Active" 
       ], 
       "timeLeft":[ 
       "P25DT2H50M35S" 
       ] 
      } 
      ], 
      "listingInfo":[ 
      { 
       "bestOfferEnabled":[ 
       "false" 
       ], 
       "buyItNowAvailable":[ 
       "false" 
       ], 
       "startTime":[ 
       "2016-03-06T22:13:42.000Z" 
       ], 
       "endTime":[ 
       "2016-07-04T22:18:42.000Z" 
       ], 
       "listingType":[ 
       "StoreInventory" 
       ], 
       "gift":[ 
       "false" 
       ] 
      } 
      ], 
      "returnsAccepted":[ 
      "true" 
      ], 
      "condition":[ 
      { 
       "conditionId":[ 
       "1000" 
       ], 
       "conditionDisplayName":[ 
       "New" 
       ] 
      } 
      ], 
      "isMultiVariationListing":[ 
      "false" 
      ], 
      "topRatedListing":[ 
      "false" 
      ] 
     }, 
     { 
      "itemId":[ 
      "291571740414" 
      ], 
      "title":[ 
      "8GB kit ram memory for Apple Mac mini (Intel Core 2 Duo 2.4GHz) DDR3 - Mid 2010" 
      ], 
      "globalId":[ 
      "EBAY-US" 
      ], 
      "primaryCategory":[ 
      { 
       "categoryId":[ 
       "170083" 
       ], 
       "categoryName":[ 
       "Memory (RAM)" 
       ] 
      } 
      ], 
      "galleryURL":[ 
      "http:\/\/thumbs3.ebaystatic.com\/m\/mfWC5GPbMTmBUhcxAnR0bpQ\/140.jpg" 
      ], 
      "viewItemURL":[ 
      "http:\/\/www.ebay.com\/itm\/8GB-kit-ram-memory-Apple-Mac-mini-Intel-Core-2-Duo-2-4GHz-DDR3-Mid-2010-\/291571740414" 
      ], 
      "paymentMethod":[ 
      "PayPal" 
      ], 
      "autoPay":[ 
      "false" 
      ], 
      "location":[ 
      "United Kingdom" 
      ], 
      "country":[ 
      "GB" 
      ], 
      "shippingInfo":[ 
      { 
       "shippingServiceCost":[ 
       { 
        "@currencyId":"USD", 
        "__value__":"0.0" 
       } 
       ], 
       "shippingType":[ 
       "Free" 
       ], 
       "shipToLocations":[ 
       "Worldwide" 
       ], 
       "expeditedShipping":[ 
       "false" 
       ], 
       "oneDayShippingAvailable":[ 
       "false" 
       ], 
       "handlingTime":[ 
       "1" 
       ] 
      } 
      ], 
      "sellingStatus":[ 
      { 
       "currentPrice":[ 
       { 
        "@currencyId":"USD", 
        "__value__":"80.21" 
       } 
       ], 
       "convertedCurrentPrice":[ 
       { 
        "@currencyId":"USD", 
        "__value__":"80.21" 
       } 
       ], 
       "sellingState":[ 
       "Active" 
       ], 
       "timeLeft":[ 
       "P9DT14H36M59S" 
       ] 
      } 
      ], 
      "listingInfo":[ 
      { 
       "bestOfferEnabled":[ 
       "false" 
       ], 
       "buyItNowAvailable":[ 
       "false" 
       ], 
       "startTime":[ 
       "2015-09-23T10:00:06.000Z" 
       ], 
       "endTime":[ 
       "2016-06-19T10:05:06.000Z" 
       ], 
       "listingType":[ 
       "FixedPrice" 
       ], 
       "gift":[ 
       "false" 
       ] 
      } 
      ], 
      "returnsAccepted":[ 
      "true" 
      ], 
      "condition":[ 
      { 
       "conditionId":[ 
       "1000" 
       ], 
       "conditionDisplayName":[ 
       "New" 
       ] 
      } 
      ], 
      "isMultiVariationListing":[ 
      "false" 
      ], 
      "topRatedListing":[ 
      "false" 
      ] 
     }, 
     { 
      "itemId":[ 
      "400584165500" 
      ], 
      "title":[ 
      "New! 8GB 2X4GB DDR3 Apple Mac Mini MC270LL\/A 2.4GHZ RAM" 
      ], 
      "globalId":[ 
      "EBAY-US" 
      ], 
      "primaryCategory":[ 
      { 
       "categoryId":[ 
       "170083" 
       ], 
       "categoryName":[ 
       "Memory (RAM)" 
       ] 
      } 
      ], 
      "galleryURL":[ 
      "http:\/\/thumbs1.ebaystatic.com\/m\/mQ8qnWSmMxlYd2WRgq4SuYQ\/140.jpg" 
      ], 
      "viewItemURL":[ 
      "http:\/\/www.ebay.com\/itm\/New-8GB-2X4GB-DDR3-Apple-Mac-Mini-MC270LL-A-2-4GHZ-RAM-\/400584165500" 
      ], 
      "paymentMethod":[ 
      "PayPal", 
      "VisaMC", 
      "AmEx", 
      "Discover" 
      ], 
      "autoPay":[ 
      "false" 
      ], 
      "postalCode":[ 
      "63122" 
      ], 
      "location":[ 
      "Saint Louis,MO,USA" 
      ], 
      "country":[ 
      "US" 
      ], 
      "shippingInfo":[ 
      { 
       "shippingServiceCost":[ 
       { 
        "@currencyId":"USD", 
        "__value__":"0.0" 
       } 
       ], 
       "shippingType":[ 
       "FlatDomesticCalculatedInternational" 
       ], 
       "shipToLocations":[ 
       "US", 
       "CA", 
       "GB", 
       "AU", 
       "AT", 
       "BE", 
       "FR", 
       "DE", 
       "IT", 
       "JP", 
       "ES", 
       "TW", 
       "NL", 
       "CN", 
       "HK", 
       "MX", 
       "DK", 
       "RO", 
       "SK", 
       "BG", 
       "CZ", 
       "FI", 
       "HU", 
       "LV", 
       "LT", 
       "MT", 
       "EE", 
       "GR", 
       "PT", 
       "CY", 
       "SI", 
       "SE", 
       "KR", 
       "ID", 
       "ZA", 
       "TH", 
       "IE", 
       "PL", 
       "RU", 
       "IL" 
       ], 
       "expeditedShipping":[ 
       "false" 
       ], 
       "oneDayShippingAvailable":[ 
       "true" 
       ], 
       "handlingTime":[ 
       "1" 
       ] 
      } 
      ], 
      "sellingStatus":[ 
      { 
       "currentPrice":[ 
       { 
        "@currencyId":"USD", 
        "__value__":"42.53" 
       } 
       ], 
       "convertedCurrentPrice":[ 
       { 
        "@currencyId":"USD", 
        "__value__":"42.53" 
       } 
       ], 
       "sellingState":[ 
       "Active" 
       ], 
       "timeLeft":[ 
       "P12DT2H42M47S" 
       ] 
      } 
      ], 
      "listingInfo":[ 
      { 
       "bestOfferEnabled":[ 
       "false" 
       ], 
       "buyItNowAvailable":[ 
       "false" 
       ], 
       "startTime":[ 
       "2013-10-05T22:05:54.000Z" 
       ], 
       "endTime":[ 
       "2016-06-21T22:10:54.000Z" 
       ], 
       "listingType":[ 
       "FixedPrice" 
       ], 
       "gift":[ 
       "false" 
       ] 
      } 
      ], 
      "returnsAccepted":[ 
      "true" 
      ], 
      "condition":[ 
      { 
       "conditionId":[ 
       "1000" 
       ], 
       "conditionDisplayName":[ 
       "New" 
       ] 
      } 
      ], 
      "isMultiVariationListing":[ 
      "false" 
      ], 
      "topRatedListing":[ 
      "false" 
      ] 
     }, 
     { 
      "itemId":[ 
      "272028972207" 
      ], 
      "title":[ 
      "8GB (2x4GB) Memory RAM 4 Apple Mac Mini 2.4GHz Intel Core 2 Duo (MC270LL\/A) DDR3" 
      ], 
      "globalId":[ 
      "EBAY-US" 
      ], 
      "primaryCategory":[ 
      { 
       "categoryId":[ 
       "170083" 
       ], 
       "categoryName":[ 
       "Memory (RAM)" 
       ] 
      } 
      ], 
      "galleryURL":[ 
      "http:\/\/thumbs4.ebaystatic.com\/m\/mWn8iDSwEnNSOPm554-dyTw\/140.jpg" 
      ], 
      "viewItemURL":[ 
      "http:\/\/www.ebay.com\/itm\/8GB-2x4GB-Memory-RAM-4-Apple-Mac-Mini-2-4GHz-Intel-Core-2-Duo-MC270LL-A-DDR3-\/272028972207" 
      ], 
      "paymentMethod":[ 
      "PayPal", 
      "VisaMC", 
      "AmEx", 
      "Discover" 
      ], 
      "autoPay":[ 
      "false" 
      ], 
      "postalCode":[ 
      "63122" 
      ], 
      "location":[ 
      "Saint Louis,MO,USA" 
      ], 
      "country":[ 
      "US" 
      ], 
      "shippingInfo":[ 
      { 
       "shippingServiceCost":[ 
       { 
        "@currencyId":"USD", 
        "__value__":"0.0" 
       } 
       ], 
       "shippingType":[ 
       "FlatDomesticCalculatedInternational" 
       ], 
       "shipToLocations":[ 
       "US", 
       "CA", 
       "GB", 
       "AU", 
       "AT", 
       "BE", 
       "FR", 
       "DE", 
       "IT", 
       "JP", 
       "ES", 
       "TW", 
       "NL", 
       "CN", 
       "HK", 
       "MX", 
       "DK", 
       "RO", 
       "SK", 
       "BG", 
       "CZ", 
       "FI", 
       "HU", 
       "LV", 
       "LT", 
       "MT", 
       "EE", 
       "GR", 
       "PT", 
       "CY", 
       "SI", 
       "SE", 
       "KR", 
       "ID", 
       "ZA", 
       "TH", 
       "IE", 
       "PL", 
       "RU", 
       "IL" 
       ], 
       "expeditedShipping":[ 
       "true" 
       ], 
       "oneDayShippingAvailable":[ 
       "true" 
       ], 
       "handlingTime":[ 
       "1" 
       ] 
      } 
      ], 
      "sellingStatus":[ 
      { 
       "currentPrice":[ 
       { 
        "@currencyId":"USD", 
        "__value__":"43.36" 
       } 
       ], 
       "convertedCurrentPrice":[ 
       { 
        "@currencyId":"USD", 
        "__value__":"43.36" 
       } 
       ], 
       "sellingState":[ 
       "Active" 
       ], 
       "timeLeft":[ 
       "P13DT23H56M49S" 
       ] 
      } 
      ], 
      "listingInfo":[ 
      { 
       "bestOfferEnabled":[ 
       "false" 
       ], 
       "buyItNowAvailable":[ 
       "false" 
       ], 
       "startTime":[ 
       "2015-10-27T19:19:56.000Z" 
       ], 
       "endTime":[ 
       "2016-06-23T19:24:56.000Z" 
       ], 
       "listingType":[ 
       "FixedPrice" 
       ], 
       "gift":[ 
       "false" 
       ] 
      } 
      ], 
      "returnsAccepted":[ 
      "true" 
      ], 
      "condition":[ 
      { 
       "conditionId":[ 
       "1000" 
       ], 
       "conditionDisplayName":[ 
       "New" 
       ] 
      } 
      ], 
      "isMultiVariationListing":[ 
      "false" 
      ], 
      "topRatedListing":[ 
      "false" 
      ] 
     }, 
     { 
      "itemId":[ 
      "221326452374" 
      ], 
      "title":[ 
      "16GB 2x8GB Memory Sodimm PC3-8500 for Mac mini (Mid 2010) 2.4GHz" 
      ], 
      "globalId":[ 
      "EBAY-US" 
      ], 
      "primaryCategory":[ 
      { 
       "categoryId":[ 
       "170083" 
       ], 
       "categoryName":[ 
       "Memory (RAM)" 
       ] 
      } 
      ], 
      "galleryURL":[ 
      "http:\/\/thumbs3.ebaystatic.com\/m\/mjmJ38XEZ8Nzz6uYL_qikVw\/140.jpg" 
      ], 
      "viewItemURL":[ 
      "http:\/\/www.ebay.com\/itm\/16GB-2x8GB-Memory-Sodimm-PC3-8500-Mac-mini-Mid-2010-2-4GHz-\/221326452374" 
      ], 
      "paymentMethod":[ 
      "PayPal" 
      ], 
      "autoPay":[ 
      "true" 
      ], 
      "location":[ 
      "USA" 
      ], 
      "country":[ 
      "US" 
      ], 
      "shippingInfo":[ 
      { 
       "shippingServiceCost":[ 
       { 
        "@currencyId":"USD", 
        "__value__":"0.0" 
       } 
       ], 
       "shippingType":[ 
       "Free" 
       ], 
       "shipToLocations":[ 
       "Worldwide" 
       ], 
       "expeditedShipping":[ 
       "false" 
       ], 
       "oneDayShippingAvailable":[ 
       "false" 
       ], 
       "handlingTime":[ 
       "3" 
       ] 
      } 
      ], 
      "sellingStatus":[ 
      { 
       "currentPrice":[ 
       { 
        "@currencyId":"USD", 
        "__value__":"58.48" 
       } 
       ], 
       "convertedCurrentPrice":[ 
       { 
        "@currencyId":"USD", 
        "__value__":"58.48" 
       } 
       ], 
       "sellingState":[ 
       "Active" 
       ], 
       "timeLeft":[ 
       "P5DT17H43M26S" 
       ] 
      } 
      ], 
      "listingInfo":[ 
      { 
       "bestOfferEnabled":[ 
       "false" 
       ], 
       "buyItNowAvailable":[ 
       "false" 
       ], 
       "startTime":[ 
       "2013-11-28T13:06:33.000Z" 
       ], 
       "endTime":[ 
       "2016-06-15T13:11:33.000Z" 
       ], 
       "listingType":[ 
       "FixedPrice" 
       ], 
       "gift":[ 
       "false" 
       ] 
      } 
      ], 
      "returnsAccepted":[ 
      "true" 
      ], 
      "condition":[ 
      { 
       "conditionId":[ 
       "3000" 
       ], 
       "conditionDisplayName":[ 
       "Used" 
       ] 
      } 
      ], 
      "isMultiVariationListing":[ 
      "false" 
      ], 
      "topRatedListing":[ 
      "false" 
      ] 
     }, 
     { 
      "itemId":[ 
      "370953309140" 
      ], 
      "title":[ 
      "New! 8GB Memory Module PC3-8500 for Mac mini (Mid 2010) 2.4GHz" 
      ], 
      "globalId":[ 
      "EBAY-US" 
      ], 
      "primaryCategory":[ 
      { 
       "categoryId":[ 
       "170083" 
       ], 
       "categoryName":[ 
       "Memory (RAM)" 
       ] 
      } 
      ], 
      "galleryURL":[ 
      "http:\/\/thumbs1.ebaystatic.com\/m\/maQbGAGXgQ3RXgZ8ictMv3g\/140.jpg" 
      ], 
      "viewItemURL":[ 
      "http:\/\/www.ebay.com\/itm\/New-8GB-Memory-Module-PC3-8500-Mac-mini-Mid-2010-2-4GHz-\/370953309140" 
      ], 
      "paymentMethod":[ 
      "PayPal" 
      ], 
      "autoPay":[ 
      "true" 
      ], 
      "location":[ 
      "USA" 
      ], 
      "country":[ 
      "US" 
      ], 
      "shippingInfo":[ 
      { 
       "shippingServiceCost":[ 
       { 
        "@currencyId":"USD", 
        "__value__":"0.0" 
       } 
       ], 
       "shippingType":[ 
       "Free" 
       ], 
       "shipToLocations":[ 
       "Worldwide" 
       ], 
       "expeditedShipping":[ 
       "false" 
       ], 
       "oneDayShippingAvailable":[ 
       "false" 
       ], 
       "handlingTime":[ 
       "3" 
       ] 
      } 
      ], 
      "sellingStatus":[ 
      { 
       "currentPrice":[ 
       { 
        "@currencyId":"USD", 
        "__value__":"32.74" 
       } 
       ], 
       "convertedCurrentPrice":[ 
       { 
        "@currencyId":"USD", 
        "__value__":"32.74" 
       } 
       ], 
       "sellingState":[ 
       "Active" 
       ], 
       "timeLeft":[ 
       "P5DT18H20M39S" 
       ] 
      } 
      ], 
      "listingInfo":[ 
      { 
       "bestOfferEnabled":[ 
       "false" 
       ], 
       "buyItNowAvailable":[ 
       "false" 
       ], 
       "startTime":[ 
       "2013-11-28T13:43:46.000Z" 
       ], 
       "endTime":[ 
       "2016-06-15T13:48:46.000Z" 
       ], 
       "listingType":[ 
       "FixedPrice" 
       ], 
       "gift":[ 
       "false" 
       ] 
      } 
      ], 
      "returnsAccepted":[ 
      "true" 
      ], 
      "condition":[ 
      { 
       "conditionId":[ 
       "1000" 
       ], 
       "conditionDisplayName":[ 
       "New" 
       ] 
      } 
      ], 
      "isMultiVariationListing":[ 
      "false" 
      ], 
      "topRatedListing":[ 
      "false" 
      ] 
     } 
     ] 
    } 
    ], 
    "paginationOutput":[ 
    { 
     "pageNumber":[ 
     "1" 
     ], 
     "entriesPerPage":[ 
     "100" 
     ], 
     "totalPages":[ 
     "1" 
     ], 
     "totalEntries":[ 
     "6" 
     ] 
    } 
    ], 
    "itemSearchURL":[ 
    "http:\/\/www.ebay.com\/sch\/i.html?_nkw=Mac+Mini+2.4ghz+8gb+ram&_ddo=1&_ipg=100&_pgn=1" 
    ] 
} 
] 
} 
+2

[내 대답] (http://stackoverflow.com/a/37602802/65863)에서 [이전 질문] (http://stackoverflow.com/questions/37595303/)에 대해 배웠습니까? 이 같은 주제? 'TJsonTexReader'로 놀아 보지 않고 실제로 어떻게 작동하는지 배웠습니까? –

+0

당연히 나는 무언가를 배웠다. 나는 모든 것을 이해했다. 그러나 나는 그것을 단지 하나의 가치로 사용하는 방법을 얻지 못했다. 나는 모든 currentprice 값을 얻기 위해 그것을 사용했기 때문에. 하지만 난 진짜로 하나만 할 방법을 모르겠다. –

+0

당신이 모든 값을 읽기 위해 배열을 사용하기 전에 당신의 대답에 있기 때문에. 그리고이 예제에서는 하나의 totalentries와 하나의 totapages가 있기 때문에 어떤 배열도 필요하지 않습니다. –

답변

0

사용 무언가 :

jData := TJSONObject.ParseJSONValue(DataString) as TJSONObject; 

거기에서 당신은 자식 개체에 액세스 할 수 있습니다 클릭하여 원하는 값을 얻는다. Sam

+0

당신의 대답에 감사 드리며 설명해 주거나 자식 객체에 액세스하여 값을 얻는 방법을 보여줄 수 있습니까? –

+0

@LiamBonactarian 필요한 모든 설명은 [여기] (http://edn.embarcadero.com/article/40882)에서 찾을 수 있습니다. 'TJSONObject'의 각 자식은 다른'TJsonObject' (존재한다면)를 반환하는'Get' 메쏘드로 접근 할 수 있습니다. – Sam

+1

이것은 무언가입니다. 기껏해야 이것은 주석입니다. 문제는 이전에 수 백 번 질문을 받고 답을 얻은 것입니다. 이 질문자가 이전에 물어 본 적이 있습니다!우리는 더 많은 답변을 필요로하지 않습니다. 특히 중요한 모든 세부 사항을 생략하는 최소한의 것들은 아니며, 주석의 오프 사이트 주제에 대한 링크를 추가하십시오. –

관련 문제