Search notes:

Simple demonstration script for using Tim Halls VBA-JSON parser

The following simple script tries to demonstrate how Tim Hall's VBA JSON parser might be used.
I wrote this script because I once was bitten by the fact(?) that the special key name values cannot be used with the exclamation point notation (jsonTest!values).
option explicit

sub jsonTest()

    dim jsonText as string
    jsonText = "{" & _
       """keyOne"": [""zero"", ""one"", ""two"", ""three""]," & _
       """keyTwo"": {""num"": 42, ""txt"": ""Hello world.""}" & _
       """values"": {""num"": 99, ""txt"": ""ninety-nine.""}" & _
    "}"

    dim jsonParsed as dictionary
    set jsonParsed = parseJson(jsonText)

  '
  ' Iterate over keys
  '
    dim k as variant
    for each k in jsonParsed
        debug.print "key = " & k
    next k

    debug.print ""

    debug.print "jsonParsed!keyOne(2)     = "   & jsonParsed!keyOne(2)
    debug.print "jsonParsed!keyTwo!num    = "   & jsonParsed!keyTwo!num
    debug.print "jsonParsed(""values"")!num = " & jsonParsed("values")!num ' jsonParsed!values does not seem to work...

    debug.print ""

    dim e as variant
    for each e in jsonParsed!keyOne
        debug.print e
    next e

end sub 
When run, this sub prints
key = keyOne
key = keyTwo
key = values

jsonParsed!keyOne(2)     = one
jsonParsed!keyTwo!num    = 42
jsonParsed("values")!num = 99

zero
one
two
three
The VBA-JSON library requires a reference for dictionary to be set.

See also

JSON

Index