Does VBA get values ​​from a collection?

I am very new to VBA and I cannot figure out how to get the values ​​from the collection.

This is my code:

Dim p As Object Set p = JSON.parse(Response.Content) Dim links As Object Set links = p.Item("links") 

In the debugger for "links" I see:

enter image description here

I use this library for json analysis: http://www.ediy.co.nz/vbjson-json-parser-library-in-vb6-xidc55680.html

Part I have in json:

 "links":[ { "rel":"next", "href":"www.google.com" } ] 

How can I get the value of "rel" here?

+3
json vba excel-vba excel vb6
07 Oct '14 at 6:08
source share
3 answers

Do not forget the bang operator, designed to access the collection using the key:

 links(1)!rel 

or

 links(1)![rel] 'When there are spaces or reserved words. 
+2
Oct 07 '14 at 18:25
source share

I will answer my question:

 links(1).Item("rel") 

worked...

Respectfully..

+3
07 Oct '14 at 11:27
source share

Using JavaScript functions to parse JSON, on top of ScriptControl, we can create a parser in VBA that will list each data point inside JSON. No matter how nested or complex the data structure is, as long as we provide a valid JSON, this analyzer will return a complete tree structure.

JavaScripts The Eval, getKeys, and getProperty methods provide building blocks for validating and reading JSON.

In combination with a recursive function in VBA, we can iterate over all keys (up to the nth level) in a JSON string. Then, using the Tree control (used in this article) or a dictionary, or even on a simple sheet, we can arrange the JSON data as needed.

You can see the full VBA code here

+1
Nov 12 '14 at 4:41
source share



All Articles