【发布时间】:2015-09-15 11:32:27
【问题描述】:
我想解析 config.json 文件并将一些特定的值放入变量中。
以下命令正在运行,它从 json 打印值:
type config.json | "jq-win64.exe" .path.editor
config.json 内容:
{ "path" : { "editor" : "...value..." } }jq 是 json 库 (https://stedolan.github.io/jq/)
问题是如何将这个值放入某个变量中?
我试过了,但没有用:
set editorPath = type config.json | "jq-win64.exe" -r .path.editor
结果是%editorPath% 为空
也许它与 jq 库(https://stedolan.github.io/jq/)有关,但我在 windows shell 中很菜鸟,所以也许有人可以帮助解决这个问题。
谢谢
【问题讨论】:
-
您可能会发现this answer 很有用。由于您的 JSON 格式正确,请从
eval行和echo editor: !editor!中删除大括号 -
一般来说,当您想将命令的输出捕获到变量时,请使用
for /F循环。for /f "delims=" %%I in ('command') do set "variable=%%I"或类似的。有关更多信息,请在 cmd 控制台中查看help for。 -
如果以下答案之一有帮助,请考虑选择一个标记为已接受。 See this page 解释为什么这很重要。
标签: json windows batch-file cmd jq