小编Scu*_*Dan的帖子

在 PowerShell 中理解 NewtonSoft

我涉足 JSON 解析和 NewtonSoft 的世界,至少可以说我很困惑。

使用以下 PowerShell 脚本:

$json = @"
{
    "Array1": [
        "I am string 1 from array1",
        "I am string 2 from array1"
    ],   

    "Array2": [
        {
           "Array2Object1Str1": "Object in list, string 1",
           "Array2Object1Str2": "Object in list, string 2"
        }
    ]

}
"@

#The newtonSoft way
$nsObj = [Newtonsoft.Json.JsonConvert]::DeserializeObject($json, [Newtonsoft.Json.Linq.JObject])

$nsObj.GetType().fullname #Type = Newtonsoft.Json.Linq.JObject

$nsObj[0] #Returns nothing. Why?

$nsObj.Array1 #Again nothing. Maybe because it contains no key:value pairs?
$nsObj.Array2 #This does return, maybe because has object with …
Run Code Online (Sandbox Code Playgroud)

powershell json json.net

2
推荐指数
1
解决办法
2988
查看次数

标签 统计

json ×1

json.net ×1

powershell ×1