Passing null
wiryonolau opened this issue · 2 comments
wiryonolau commented
Hi, How do I pass null value ? I need convertToJson result to be as as null instead of "null"
Dim payload As New Dictionary
' How to set id to null.
' vbNullString, vbNull become 1 instead of null
' vbEmpty become 0
payload.Add "id", "null"
payload.Add "provider", "something"
payload.Add "name", "someone"
JsonConverter.ConvertToJson(payload)
Nick-vanGemeren commented
vbNullString
is a string constant of zero length, a but more efficient than its equivalent literal""
.
vbNull is a constant = 1 returned byVarType()
when the variable has no valid data. You can use it on the receiving (ParseJson
) side in code like
If VarType(jsonObject("error")) <> vbNull Then
To send a null value , simply use Null directly or via a Variant.
Sub Test()
Dim payload As New Dictionary
Dim nullvar As Variant: nullvar = Null
payload.Add "id", nullvar
payload.Add "name", "someone"
Debug.Print JsonConverter.ConvertToJson(payload)
' =>{"id":null,"name":"someone"}
End Sub
If this solves your problem, please close your issue here.
wiryonolau commented
Ok it's working. Thanks.