vb.net - 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 中使用波纹管方法解决了这个 json 验证问题。
Dim hasJsonData = jsonObj("mstSigmaVos").count
If hasJsonData > 0 Then
'Do something
EndIf
但是仍然困惑为什么那些VB验证“IsNot Nothing”,“Not Is Nothing”不起作用。
推荐阅读
- linux - 小型嵌入式系统上主要应用程序的核心转储
- react-native - Javascript 捆绑器构建停留在 99%
- sql - 这可以在 Oracle SQL 中计算 p 值吗?
- python-3.x - 如何将 python FTP 服务器设为 PUBLIC?
- python - 如何检查 json 列表中是否有属性?如果没有我该如何添加它只在缺少的地方?
- if-statement - 有没有办法使用 Liquid 和条件语句根据当前页面的名称设置 CSS 类?
- ruby-on-rails - 在 for 循环中执行 mongo find 会导致它崩溃吗?
- sql - 复制行和另一个表中的依赖行,以及另一个表中的依赖行等
- javascript - 如何编写正确缩进方案代码的 JavaScript 函数?
- swift - 在协议中实现某种形式的枚举