VBA getting values from a collection?

后端 未结 3 1366
情书的邮戳
情书的邮戳 2020-12-10 19:14

I am very new to VBA and I can not figure out how to get values from a Collection.

This is my code:

Dim p As Object
Set p = JSON.parse(Response.Conte         


        
相关标签:
3条回答
  • 2020-12-10 19:34

    Don't forget the bang operator, designed for collection access by key:

    links(1)!rel
    

    or:

    links(1)![rel] 'When there are spaces or reserved words.
    
    0 讨论(0)
  • 2020-12-10 19:41

    Using JavaScript features of parsing JSON, on top of ScriptControl, we can create a parser in VBA which will list each and every data point inside the JSON. No matter how nested or complex the data structure is, as long as we provide a valid JSON, this parser will return a complete tree structure.

    JavaScript’s Eval, getKeys and getProperty methods provide building blocks for validating and reading JSON.

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

    You can see the full VBA code here

    0 讨论(0)
  • 2020-12-10 19:47

    I will answer my own question:

    links(1).Item("rel")
    

    worked...

    Regards..

    0 讨论(0)
提交回复
热议问题