RC6.Collection is somewhat inconvenient when dealing with the null/empty value of JSON objects, for example:
I need to do the following processing:
It's recommended to add an optional parameters to RC6.Collection.Prop:
When id does not exist or is null, return Nothing:
Code:
Dim oID As Object
Dim oJSON As cCollection
Set oJSON = New_c.JSONObject
Set oJSON = New_c.JSONDecodeToCollection("{""id"": null}")
Set oID = oJSON.Prop("id") '--- Run-time error: Object required ---
Code:
If oJSON.Exists("id") = False Then
Set oID = Nothing
ElseIf IsEmpty(oJSON.Prop("id")) = True Then
Set oID = Nothing
Else
Set oID = oJSON.Prop("id")
End If
Code:
Property Prop(Key, Optional ByVal IsObject As Boolean)
'OR
Property Prop(Key, Optional ByVal NullIsNothing As Boolean)
Code:
Set oID = oJSON.Prop("id", True) '--- When id does not exist or is null, return Nothing ---