JSONParser
Class to parse a JSON string to a VBA data structure. A JSON object is converted to a Dictionary and an array to a Collection .
Class: JSONParser
Remarks
- Numeric values are converted to Double datatype.
- Dates are treated as a String by default unless the property ConvertToDate is set to True .
Example
Dim JP As New JSONParser
Dim varData As Variant
With JP
' Content of file:
' {
' "name" : "Jeff Morrisson",
' "salary" : 28334.33,
' "dateofbirth" : "1988-11-24",
' "male" : true,
' "children" : [ "Anna", "Kim", "Alex" ]
' }
.Filename = "C:\test.json"
.DebugResult = True
Set varData = .Parse
If varData Is Nothing Then
MsgBox "JSON Parse failed : " & .LastError
Else
MsgBox varData("name") 'Jeff Morrisson
End If
End With
'Setting the DebugResult property to True will produce:
'
'JSON Parser
'===========
'JSON : {"name" : "Jeff Morrisson","salary" : 28334.33, "dateofbirth" : "1988-11-24","male" : true,"children" : [ "Anna", "Kim", "Alex" ]}
'Result_______: Success!
'Return type__: Dictionary
'Content:
'
'Name__________Type__________Value
'name__________String________Jeff Morrisson
'salary________Double________ 28334,33
'dateofbirth___String________1988-11-24
'male__________Boolean_______True
'children______Collection____...
'
Changelog
Date | Changes |
---|---|
2019-08-28 | Decimal point is determined by checking system settings instead of hard coded comma. |