0

私は学習目的のツールに取り組んでおり、Google API で検索を実行します。HTTPSocket を使用して、検索結果を json 形式で取得し、CharcoalDesign.co.uk によって作成された json.parser を使用して辞書に解析します。

json の結果は次のようになります。

{"responseData": {
 "results": [
  {
   "GsearchResultClass": "GwebSearch",
   "unescapedUrl": "http://en.wikipedia.org/wiki/Paris_Hilton",
   "url": "http://en.wikipedia.org/wiki/Paris_Hilton",
   "visibleUrl": "en.wikipedia.org",
   "cacheUrl": "http://www.google.com/search?q\u003dcache:TwrPfhd22hYJ:en.wikipedia.org",
   "title": "\u003cb\u003eParis Hilton\u003c/b\u003e - Wikipedia, the free encyclopedia",
   "titleNoFormatting": "Paris Hilton - Wikipedia, the free encyclopedia",
   "content": "\[1\] In 2006, she released her debut album..."
  },
  {
   "GsearchResultClass": "GwebSearch",
   "unescapedUrl": "http://www.imdb.com/name/nm0385296/",
   "url": "http://www.imdb.com/name/nm0385296/",
   "visibleUrl": "www.imdb.com",
   "cacheUrl": "http://www.google.com/search?q\u003dcache:1i34KkqnsooJ:www.imdb.com",
   "title": "\u003cb\u003eParis Hilton\u003c/b\u003e",
   "titleNoFormatting": "Paris Hilton",
   "content": "Self: Zoolander. Socialite \u003cb\u003eParis Hilton\u003c/b\u003e..."
  },
  ...
 ],
 "cursor": {
  "pages": [
   { "start": "0", "label": 1 },
   { "start": "4", "label": 2 },
   { "start": "8", "label": 3 },
   { "start": "12","label": 4 }
  ],
  "estimatedResultCount": "59600000",
  "currentPageIndex": 0,
  "moreResultsUrl": "http://www.google.com/search?oe\u003dutf8\u0026ie\u003dutf8..."
 }
}
, "responseDetails": null, "responseStatus": 200}

「results」の各値をループしてリストボックスにデータを追加したいという問題で、他のresponseData(「cursor」など)は追加しません。

Dim d as Dictionary
Dim c as Collection 

data = Json.parse(content) // use the class json.parse
d = data.Value("responseData")
c = d.Value("results")

その後、各「結果」値をループする方法がわかりません。for-eachで多くの方法を試しました...「d.Keys()の各キーに対して」辞書では機能しますが、コレクションでは機能しません。どこが間違っていますか?

4

1 に答える 1

1

コレクションをループするには、Items 関数を介してコレクションにアクセスする必要があります。

for i as integer = 1 to c.count //Collection is 1 based
   dim s as string
   s = c.item(i)
next
于 2010-10-26T17:48:48.250 に答える