I have JSON data in this form [{"word":"something", "id":1023] How can I get the value of word from the JSON data using Visual Basic? Thanks.
1 Answer
Grab a copy of this project, add it to your VBA project. You'll need to add a reference to Microsoft Scripting Runtime for this to work as the results from the parsed string get stored in a Dictionary. Once that's done, you can parse JSON, like this:
Sub ParseSomeJson()
Dim jsonString As String
Dim json As Object
jsonString = "{""word"":""something"", ""id"":1023}" 'I adjusted this
Set json = JsonConverter.ParseJson(jsonString)
Debug.Print json("word"), json("id")
End Sub
You'll get back:
something 1023
1 Comment
Mathieu Guindon
Note that Tim Hall also wrote a drop-in replacement for
Scripting.Dictionary (also found under that VBA-TOOLS GitHub org), that works off the Scripting Runtime on Windows, and works on a Mac.