Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15785

About RC6.Collection.Prop (JSONObject.Prop)

$
0
0
RC6.Collection is somewhat inconvenient when dealing with the null/empty value of JSON objects, for example:

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 ---

I need to do the following processing:

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

It's recommended to add an optional parameters to RC6.Collection.Prop:
Code:

Property Prop(Key, Optional ByVal IsObject As Boolean)

'OR

Property Prop(Key, Optional ByVal NullIsNothing As Boolean)

When id does not exist or is null, return Nothing:
Code:

Set oID = oJSON.Prop("id", True)    '--- When id does not exist or is null, return Nothing ---

Viewing all articles
Browse latest Browse all 15785

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>