如何将指定格式TXT解析为JSON?PowerShell技术咨询
问题:将特定格式TXT解析为JSON及PowerShell命令相关疑问
需求说明
我花了一整天尝试解决这个问题,恳请帮助!需要将以下格式的TXT文件解析为指定结构的JSON。
输入TXT格式
============ Get Mouse Position =============== Get Mouse Position GetMousePos Get the mouse position first Command one Command two Command three ============ Set Mouse Position =============== Set Mouse Position SetMousePos Set the mouse position after Command one Command two Command three
目标JSON输出
{ "Get Mouse Position": { "Trigger": "GetMousePos", "Description": "Get the mouse position first", "body": [ "Command one", "Command two", "Command three" ] }, "Set Mouse Position": { "Trigger": "SetMousePos", "Description": "Set the mouse position after", "body": [ "Command one", "Command two", "Command three" ] } }
遇到的问题
- 使用
ConvertFrom-StringData命令尝试过,结果接近需求,但该命令似乎不支持单键对应数组(即Command one这类列表内容)。 - 使用
PSCustomObject结合ConvertTo-Json可以生成完全符合要求的JSON,但无法编写批量处理所有===== [Object] =====这类区块的代码。
疑问
ConvertFrom-StringData命令是否不支持单键对应多值/数组?
内容的提问来源于stack exchange,提问作者hellen_dorandt89
相关产品推荐
相关产品推荐

