如何使用Windows命令行将JSON文件解析为变量? [英] How to parse a JSON file to variables with the windows command line?

查看:653
本文介绍了如何使用Windows命令行将JSON文件解析为变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为test.jsonJSON文件,其中说:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆