检查 Newtonsoft.Json.Linq.JToken 是否为空
Check if Newtonsoft.Json.Linq.JToken is nothing
根据调试器,我有一个名为 myCancelled
的变量,类型为 Newtonsoft.Json.Linq.Jtoken,值为 Nothing。我也将它转换为 Object 并且所有这些条件都失败了。我的问题很简单:如何检查它是否为 Nothing/Null/False/Empty?
这是我试过的方法。 None 这些条件的计算结果为真:
If myCancelled Is Nothing Then
'Doesn't come here
End If
If myCancelled = DBNull.Value.ToString Then
'Doesn't come here
End If
If myCancelled = "null" Then
'Doesn't come here
End If
If IsDBNull(myCancelled) Then
'Doesn't come here
End If
If myCancelled Is DBNull.Value Then
'Doesn't come here
End If
If String.IsNullOrEmpty(myCancelled) = True Then
'Doesn't come here
End If
If myCancelled.ToString = "Nothing" Then
'Runtime error
End If
If myCancelled = DBNull.Value Then
'Runtime error
End If
If IsNothing(myCancelled) Then
'Doesn't come here
End If
我是 VB.net 的新手,非常感谢任何指点。
编辑
这个有效,但它会让误报通过(当 myCancelled 具有它的值时,条件为真)
If Not myCancelled Then
' It comes here
End If
这是有效的。 VB习惯了Java、C#等就很难学了
If Not myCancelled.Equals("Y") Then
' It finally came here
End If
根据调试器,我有一个名为 myCancelled
的变量,类型为 Newtonsoft.Json.Linq.Jtoken,值为 Nothing。我也将它转换为 Object 并且所有这些条件都失败了。我的问题很简单:如何检查它是否为 Nothing/Null/False/Empty?
这是我试过的方法。 None 这些条件的计算结果为真:
If myCancelled Is Nothing Then
'Doesn't come here
End If
If myCancelled = DBNull.Value.ToString Then
'Doesn't come here
End If
If myCancelled = "null" Then
'Doesn't come here
End If
If IsDBNull(myCancelled) Then
'Doesn't come here
End If
If myCancelled Is DBNull.Value Then
'Doesn't come here
End If
If String.IsNullOrEmpty(myCancelled) = True Then
'Doesn't come here
End If
If myCancelled.ToString = "Nothing" Then
'Runtime error
End If
If myCancelled = DBNull.Value Then
'Runtime error
End If
If IsNothing(myCancelled) Then
'Doesn't come here
End If
我是 VB.net 的新手,非常感谢任何指点。
编辑
这个有效,但它会让误报通过(当 myCancelled 具有它的值时,条件为真)
If Not myCancelled Then
' It comes here
End If
这是有效的。 VB习惯了Java、C#等就很难学了
If Not myCancelled.Equals("Y") Then
' It finally came here
End If