I've looked at the examples on stack overflow and vba JSON parser : https://github.com/VBA-tools/VBA-JSON . I can't work out how to parse this complex JSON:
{
"au": {
"success": true,
"data": {
"events": {
"Chicago Bulls_Orlando Magic": {
"participants": ["Chicago Bulls",
"Orlando Magic"],
"commence": "1489017900",
"status": "Pending",
"sites": {
"sportsbet": {
"odds": {
"h2h": ["1.86",
"1.99"]
},
"last_update": 1488956952
},
"tab": {
"odds": {
"h2h": ["1.70",
"2.10"]
},
"last_update": 1488957101
},
"crownbet": {
"odds": {
"h2h": ["1.83",
"1.98"]
},
"last_update": 1488957104
},
"williamhill": {
"odds": {
"h2h": ["1.83",
"2.00"]
},
"last_update": 1488957115
}
}
}
}
}
}
}
My goal is to get the event participants details into 1 database table and the sites data into its own table. I've followed the examples in GitHub but can only get to "Chicago Bulls_Orlando Magic". Where am I going wrong?
Public Function ScanJson()
Dim FSO As New FileSystemObject
Dim JsonTS As TextStream
Dim JsonText As String
Dim Parsed As Dictionary
Dim strPath As String
Dim blnSuccess As Boolean
strPath = CurrentProject.Path & "\test_Json.txt"
' Read .json file
Set JsonTS = FSO.OpenTextFile(strPath, ForReading)
JsonText = JsonTS.ReadAll
JsonTS.Close
'clean string
JsonText = Replace(JsonText, vbCrLf, "")
JsonText = Replace(JsonText, vbTab, "")
' Parse json to Dictionary
' "values" is parsed as Collection
' each item in "values" is parsed as Dictionary
Set Parsed = JsonConverter.ParseJson(JsonText)
'test theres data
blnSuccess = Parsed("au")("success")
If blnSuccess Then
For Each Value In Parsed("au")("data")
On Error Resume Next
Debug.Print Value("events")
Debug.Print Value("events")(0)(1)
Debug.Print Value("participants")(0)
Debug.Print Value("participants")(1)
Debug.Print Value("commence")
Debug.Print Value("status")
Next Value
Else
MsgBox "No data for Key: AU "
End If
End Function