如何解决“jq: error (at <stdin>:0): cannot index number with string "description"”

问题描述

我使用以下脚本获取 GitLab 中组的描述。

脚本:

#! /bin/bash


GIT_API="https://git.xxxxxxxxxx.lk/api/v4"
GIT_TOKEN="xxxxxxxxxxxx"

curl -sS --request GET --header "PRIVATE-TOKEN: $GIT_TOKEN" "$GIT_API/groups/1079" | jq -r ".[] .description"

但它输出以下错误

jq: error (at <stdin>:0): Cannot index number with string "description"

如何解决这个问题。

卷曲输出

{
  "id": 1079,"web_url": "https://git.xxxxxxxxxx.lk/groups/testdevops","name": "testdevops20","path": "testdevops","description": "Test_1","visibility": "private","share_with_group_lock": false,"require_two_factor_authentication": false,"two_factor_grace_period": 48,"project_creation_level": "developer","auto_devops_enabled": null,"subgroup_creation_level": "maintainer","emails_disabled": null,"mentions_disabled": null,"lfs_enabled": true,"default_branch_protection": 1,"avatar_url": null,"request_access_enabled": true,"full_name": "testdevops20","full_path": "testdevops","created_at": "2021-05-31T04:56:28.467Z","parent_id": null,"shared_with_groups": [],"runners_token": "Dw_LPVsbeChD6s6n1wRy","projects": []
}

解决方法

修改脚本如下:

#! /bin/bash


GIT_API="https://git.xxxxxxxxxx.lk/api/v4"
GIT_TOKEN="xxxxxxxxxxxx"

curl -sS --request GET --header "PRIVATE-TOKEN: $GIT_TOKEN" "$GIT_API/groups/1079" | jq -r ".description"

jq 命令在写为 jq -r ".description" 时有效。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...