首页 > 解决方案 > Visual Basic 中的 jsonObject 空检查

问题描述

    url = loginInfo.settings.apiUrl & "sigma?machineId=" & If(production.machineId IsNot Nothing, Uri.EscapeDataString(production.machineId), Nothing)
    Dim jsonObj = Common.GetJson(url, loginInfo.token)

我有一个 jsonObject,它通过 url 和 Getjson 方法获取数据。Empty JsonObj 格式给出了下面的主要模型是“mstSigmaVos”

{
  "type": "mstSigmaList",
  "error": false,
  "mstSigmaVos": [],
  "resourceMap": {
  "entry": []
 }
}

以前我已经验证了上面的 jsobObj 就像下面的代码不起作用。

   If Not jsonObj("mstSigmaVos") Is Nothing Then
        'Do Something
    End If

我的问题是,为什么

If Not jsonObj("mstSigmaVos") Is Nothing Then
  'Do something
EndIf 

或者

 If jsonObj("mstSigmaVos")IsNot Nothing" Then
  'Do something
 EndIf 

这些检查不适用于 jsonObj 检查 vb?

标签: vb.net

解决方案


我已经通过在 vb 中使用波纹管方法解决了这个 json 验证问题。

 Dim hasJsonData = jsonObj("mstSigmaVos").count
 If hasJsonData > 0 Then
  'Do something
 EndIf

但是仍然困惑为什么那些VB验证“IsNot Nothing”,“Not Is Nothing”不起作用。


推荐阅读