2010-10-26 15 views
0

我正在學習目的的工具上工作,它使用google apis執行搜索。使用HTTPSocket我得到JSON格式的搜索結果,然後分析它與CharcoalDesign.co.uk使用Realbasic Loop集合

這是寫在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} 

問題我想循環每個「結果」的值並將數據添加到列表框,而不添加任何其他responseData(如「光標」)。

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") 

之後,我不知道如何循環的每一個「結果」的價值,我已經tryed與-每...用字典工作的方法很多,「在每一個運行起來也鍵()」 ,但沒有收集。我錯在哪裏?

回答

1

要遍歷集合,您需要通過Items函數訪問它。

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

@BKeeney:謝謝!現在我已經理解了在集合循環中使用的正確的合成器,但是我的代碼出現了問題......我在「s = c.item(i)」上出現錯誤。這是從d.dictionary c.collection的正確方法嗎? – Luciano 2010-10-26 19:24:58

+0

那麼,我從來沒有使用過CharcoalDesign json解析器。只是猜測,但嘗試使用這樣的事情:dim s as string = d.value(「results」) – 2010-10-27 14:06:19

+0

或dim v as variant = d.value(「results」)並查看調試器以查看它返回的內容。 – 2010-10-27 14:07:25