Collections 使用Realbasic循环集合

Collections 使用Realbasic循环集合,collections,dictionary,realbasic,Collections,Dictionary,Realbasic,我正在开发一个用于学习的工具,它使用谷歌API执行搜索。我使用HTTPSocket以json格式获得搜索结果,然后使用CharcoalDesign.co.uk编写的json.parser将其解析到字典中 以下是json结果的外观: {"responseData": { "results": [ { "GsearchResultClass": "GwebSearch", "unescapedUrl": "http://en.wikipedia.org/wiki/Paris_Hil

我正在开发一个用于学习的工具,它使用谷歌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”)


在那之后,我不知道如何循环每个“结果”值,我已经尝试了很多方法来实现每个。。。适用于字典“d.Keys()中的每个键”,但不适用于集合。我错在哪里?

要在集合中循环,需要通过Items函数访问它

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

@谢谢!现在我已经了解了在集合循环中使用的正确synthax,但是我的代码有点问题。。。我在“s=c.item(i)”行中得到一个错误。这是d.dictionary中的c.collection的正确方法吗?我从来没有使用过CharcoalDesign json解析器。只是猜测一下,但试着使用这样的东西:dim s as string=d.value(“结果”)或dim v as variant=d.value(“结果”)并查看调试器中返回的内容。使用循环,我得到s为nil。尝试将dim s设置为string=d.value(“结果”),s为空字符串。而v作为variant=d.value(“结果”),v是计数为4的集合。再次感谢你的帮助@Bkeeney,很高兴在StackOverflow上见到你;)
for i as integer = 1 to c.count //Collection is 1 based
   dim s as string
   s = c.item(i)
next