You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

KQL解析JSON数组异常:parse_json、todynamic均无法获取Username字段

问题根因

DeviceInfo表内置的LoggedOnUsers字段本身为用户对象数组结构,并非单个JSON对象。使用todynamic转换得到的AllProperties为数组类型,直接对数组执行["Username"]属性索引无法命中有效值,所以返回空结果。

修复方案

根据你的使用场景选择对应写法即可:

  • 场景1:需要导出所有登录用户的用户名,每个用户单独对应一行记录
DeviceInfo
| where RegistryDeviceTag == "Standard"
| extend AllProperties = todynamic(LoggedOnUsers)
| mv-expand AllProperties
| project DeviceName, Users = AllProperties.Username
  • 场景2:仅需要取第一条登录记录的用户名
DeviceInfo
| where RegistryDeviceTag == "Standard"
| extend AllProperties = todynamic(LoggedOnUsers)
| project DeviceName, Users = AllProperties[0].Username
验证方法

你可以先运行以下查询确认字段结构,若gettype返回值为array即可确认上述问题判断准确:

DeviceInfo
| where RegistryDeviceTag == "Standard"
| extend AllProperties = todynamic(LoggedOnUsers)
| project AllProperties, field_type = gettype(AllProperties)

内容的提问来源于stack exchange,提问作者John418

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.11 10:48:01