如何使用Windows命令行将JSON文件解析为变量? [英] How to parse a JSON file to variables with the windows command line?
问题描述
我有一个名为test.json
的JSON
文件,其中说:
I have this JSON
file called test.json
which says:
{
"test":true,
"limit":
{
"min":0.5,
"max":1.5
}
}
我希望能够在Windows命令行中读取此文件,并将这些对象解析为变量.
I'd like to be able to read this file in the Windows command line and have these objects parsed as variables.
我该怎么做?
推荐答案
如果使用Windows Powershell作为命令行,则可以使用ConvertFrom-JSON
cmdlet:
If you use Windows Powershell as your command line, you can use the ConvertFrom-JSON
cmdlet: http://powershelljson.codeplex.com/
确保您的PowerShell版本高于3.0,如 ConvertFrom-JSON可以从该版本中获得.
Make sure your PowerShell version is above 3.0, as ConvertFrom-JSON is available from that version.
如果使用普通的老式CMD,则需要使用外部工具.我喜欢jq: http://stedolan.github.io/jq/.本教程使用curl
作为示例,但是您可以轻松地使用echo
或从文件中读取JSON.
If you use plain old CMD, you'll need an external tool for it. I like jq: http://stedolan.github.io/jq/. The tutorial uses curl
for the examples, but you can just as easily use echo
or read the JSON from a file.
这篇关于如何使用Windows命令行将JSON文件解析为变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!