开发者

Loop a collection with Realbasic

I'm work on a tool for learning purposes, it perform a search with google apis. Using HTTPSocket I get the results of the search in json format and then parse it to dictionary with the json.parser written by CharcoalDesign.co.uk

This is how looks json results:

{"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}

The problem that i want to loop each value of "results" and add data to a listbox, without adding any other responseData (such as "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")

After that i dont know how to loop each of "results" value, i've tryed many ways with for-each... works with dictionary, "for each key in d.Keys()", but not with colle开发者_StackOverflow中文版ction. Where i'm wrong?


To loop through a collection you need to access it through the Items function.

for i as integer = 1 to c.count //Collection is 1 based
   dim s as string
   s = c.item(i)
next
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜