【问题标题】:Parsing json using jq使用 jq 解析 json
【发布时间】:2013-10-31 10:25:59
【问题描述】:

我正在尝试在 linux 命令行上使用 jq 从 JSON 结构中获取难度值:

./jq '{result: .difficulty}' status.txt

(JSON 保存在一个名为 status.txt 的文件中 - 如下所示)但尽我所能尝试:

{
  "result": null
}

返回,谁能告诉我我做错了什么?

{
   "result":{
      "version":1030000,
      "protocolversion":60001,
      "walletversion":60000,
      "balance":2600.00020000,
      "blocks":16042,
      "connections":6,
      "proxy":"",
      "difficulty":28.20775972,
      "testnet":false,
      "keypoololdest":1382340615,
      "keypoolsize":94,
      "paytxfee":0.00000000,
      "mininput":0.00010000,
      "unlocked_until":0,
      "errors":""
   },
   "error":null,
   "id":"curltest"
}

【问题讨论】:

    标签: json parsing jq


    【解决方案1】:

    尝试访问result 对象并在其中提取difficulty 值:

    ./jq '.result.difficulty' status.txt
    

    它产生:

    28.20775972
    

    【讨论】:

    • 我应该怎么做才能检索到IDcurltest 值。使用 for 循环时遇到问题
    猜你喜欢
    • 2020-11-07
    • 1970-01-01
    • 2018-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多