我实际上试图从下面的json代码(idhttp.get的响应来自ebay api查找调用)获取totalentries(在json结尾处)值。我实际上是这样想的:有人能帮我吗?德尔福从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"
]
}
]
}
你没有从[我的回答](http://stackoverflow.com/a/37602802/65863)到你[上一个问题](http://stackoverflow.com/questions/37595303/)同样的话题?你有没有玩过'TJsonTexReader'并了解它是如何工作的? –
当然,当然,我学到了一些东西,我理解了一切,但我没有得到如何使用它只有一个值。因为我用它来获取所有当前价格值。但我真的不知道如何去做只有一个... –
因为在你使用数组读取所有值之前的答案。在这个例子中,我不需要任何数组,因为只有一个totalalentries和一个totapages –