首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Realbasic循环集合

使用Realbasic循环集合
EN

Stack Overflow用户
提问于 2010-10-27 01:23:55
回答 1查看 1.4K关注 0票数 0

我正在研究一个用于学习目的的工具,它使用google apis执行搜索。我使用HTTPSocket获得json格式的搜索结果,然后使用CharcoalDesign.co.uk编写的json.parser将其解析到字典中

这是json结果的样子:

代码语言:javascript
复制
{"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“)。

代码语言:javascript
复制
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")

在那之后,我不知道如何循环每个"results“值,我已经尝试了许多方法,使用for- each…使用字典,"for each key in d.Keys()",但不使用集合。我哪里错了?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-10-27 01:48:48

要遍历集合,需要通过Items函数访问它。

代码语言:javascript
复制
for i as integer = 1 to c.count //Collection is 1 based
   dim s as string
   s = c.item(i)
next
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4026197

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档