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

PowerShell:ConvertFrom-Json处理单元素字符串数组返回结果异常

PowerShell ConvertFrom-Json 参数行为差异记录

假设文件 array.json 的内容为:

["bogus"]

执行以下PowerShell命令及对应输出:

PS C:\Users\Me> (Get-Content "array.json" | ConvertFrom-Json -NoEnumerate).GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Object[]                                 System.Array
PS C:\Users\Me> (Get-Content "array.json" | ConvertFrom-Json).GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     String                                   System.Object

上述结果存在反直觉差异:使用 -NoEnumerate 参数转换时,返回的是 Object[] 类型的数组;而直接调用 ConvertFrom-Json 转换,返回的却是 String 类型。特此记录,帮助他人避免此类困惑。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 14:53:20