首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用curl (qBittorrent Web )过滤数组

使用curl (qBittorrent Web )过滤数组
EN

Stack Overflow用户
提问于 2022-10-04 11:02:38
回答 1查看 126关注 0票数 0

希望有人能帮我。我在试着理解qBittorrent网络API。目前,我正在列出所有暂停的洪流:

代码语言:javascript
复制
curl -i http://localhost:8080/api/v2/torrents/info?category=test

问题是,列出了整个JSON数组--我的问题是,我能否只显示"name“或”散列“字段?这都是通过cmd使用curl的,但是我已经在Git Bash &Powershell中尝试过这样的方法:

代码语言:javascript
复制
[{"eta":8640000,"f_l_piece_prio":false,"force_start":false,"hash":"8419d48d86a14335c83fdf4930843438a2f75a6b","last_activity":1664863523,"magnet_uri":"","max_seeding_time":0,"**name**":"TestTorrentName","num_complete":12,"num_incomplete":1,"num_leechs":0,"num_seeds":0,"priority":0,"progress":1,"ratio":0,"ratio_limit":-2,"save_path":"F:\\Completed\\test\\","seeding_time":0,"seeding_time_limit":-2,"seen_complete":1664863523,"seq_dl":false,"size":217388295,"state":"pausedUP","super_seeding":false,"tags":"","time_active":569,"total_size":217388295,"tracker":"udp://open.stealth.si:80/announce","trackers_count":10,"up_limit":-1,"uploaded":0,"uploaded_session":0,"upspeed":0}]

根据https://jqplay.org/,我已经尝试了以下几种应该有效的方法--参见屏幕截图

代码语言:javascript
复制
curl -i http://localhost:8080/api/v2/torrents/info?category=test | jq --raw-output '.[] | .name'

但不幸的是,我得到了以下错误:

代码语言:javascript
复制
curl -i http://localhost:8080/api/v2/torrents/info?category=test | jq --raw-output '.[] | .name'
  % Total    % Received % Xferd  Average Speed   Time    '.name'' is not recognized as an internal or external command,
operable program or batch file.
Ti
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-10-04 11:32:55

代码语言:javascript
复制
curl -i http://localhost:8080/api/v2/torrents/info?category=test | jq --raw-output '.[] | .name'

-i让curl提供一些头部信息,这些信息被解析为jq,但是jq只能解析JSON,因此失败。

删除-i,并将其替换为-s以删除统计数据:

代码语言:javascript
复制
curl -s http://localhost:8080/api/v2/torrents/info?category=test | jq --raw-output '.[] | .name'
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73946917

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档