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

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758186174, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/VBA/libraries/JSON/Tim-Hall/index(95): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78