-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJSonUtilities.bas
More file actions
70 lines (57 loc) · 2.18 KB
/
JSonUtilities.bas
File metadata and controls
70 lines (57 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
Attribute VB_Name = "JSonUtilities"
'@Folder("JSON")
Option Explicit
Private Const ModuleName As String = "JSonUtilities"
Public Enum JsonExceptionEnum
JsonExceptionUnexpectedKey = vbObjectError + 50
JsonExceptionUnexpectedCharacter = vbObjectError + 51
JsonExceptionUnexpectedToken = vbObjectError + 52
End Enum
Public Enum JsonDataTypeEnum
JsonDataTypeObject
jsondatatypeArray
JsonDataTypeString
JsonDataTypeNumber
JsonDataTypeBoolean
JsonDataTypeNull
End Enum
'@Description "Check if the key Key exist within the collection Col"
Public Function ExistInCollection(ByVal Key As String, ByVal Col As Object) As Boolean
Attribute ExistInCollection.VB_Description = "Check if the key Key exist within the collection Col"
Const FunctionName As String = "ExistInCollection"
Dim ErrorLogger As ErrorLogger
Set ErrorLogger = Factory.CreateErrorLogger(ModuleName, FunctionName)
ExistInCollection = ExistInCollectionByVal(Key, Col) Or ExistInCollectionByRef(Key, Col)
End Function
Private Function ExistInCollectionByVal(ByVal Key As String, ByVal Col As Object) As Boolean
On Error GoTo Error
Const FunctionName As String = "ExistInCollectionByVal"
Dim ErrorLogger As ErrorLogger
Set ErrorLogger = Factory.CreateErrorLogger(ModuleName, FunctionName)
Dim Item As Variant
Item = Col(Key)
ExistInCollectionByVal = True
Exit Function
Error:
Err.Clear
ExistInCollectionByVal = False
End Function
Private Function ExistInCollectionByRef(ByVal Key As String, ByVal Col As Object) As Boolean
On Error GoTo Error
Const FunctionName As String = "ExistInCollectionByRef"
Dim ErrorLogger As ErrorLogger
Set ErrorLogger = Factory.CreateErrorLogger(ModuleName, FunctionName)
Dim Item As Variant
Set Item = Col(Key)
ExistInCollectionByRef = True
Exit Function
Error:
Err.Clear
ExistInCollectionByRef = False
End Function
Public Function GetAs(ByVal Item As IJson, ByVal DataType As JsonDataTypeEnum) As IJson
Const FunctionName As String = "GetAs"
Dim ErrorLogger As ErrorLogger
Set ErrorLogger = Factory.CreateErrorLogger(ModuleName, FunctionName)
Set GetAs = Service.GetAs(Item, DataType)
End Function