我正在尝试为 PowerShell 使用 HJSON C# 库:https ://github.com/hjson/hjson-cs 我已成功编译 dll,将其放入文件夹并通过标准过程添加类型:
#LOAD
$scriptRoot = Split-Path $script:psEditor.GetEditorContext().CurrentFile.Path
$FilePath = ( Get-Item .\Hjson.dll ).FullName
[System.Reflection.Assembly]::LoadFrom("$FilePath")
[Hjson.IJsonReader]::new()
[Hjson.hjson]::Load("$scriptRoot\test.hjson")
我正在尝试通过示例来了解基础知识:
读取方法:https ://github.com/hjson/hjson-cs#read
# var jsonObject = HjsonValue.Load(filePath).Qo();
$jsonTempData = [Hjson.HjsonValue]::Load("$scriptRoot\test.hjson")
$jsonObject = [Hjson.JsonUtil]::Qo($jsonTempData)
$jsonObject
但输出缺少值:
PS D:\OneDrive\PS-HJSON> $jsonObject
Key Value
--- -----
hello
text
quote
otherwise
abc-123
commas
but
trailing
multiline
number
negative
yes
no
null
array
array2
PS D:\OneDrive\PS-HJSON>
所以我看不到价值。为什么它不像 JSON 对象那样工作?
当我尝试遍历键时:
foreach ( $item in $jsonObject) {
$item.Key, $item.Value
}
我懂了:
尝试枚举集合时发生以下异常:“由于对象的当前状态,该操作无效。”
我确定我遗漏了一些东西,但我对 c# 的了解还不够,不知道该怎么做。