首页 > 解决方案 > curl GET json 文件:输出文件具有附加字符串“文本”和特殊字符,如“\”

问题描述

也许有人可以通过curl请求支持我吗?我正在调用 Bitbucket (v 1.0) 的 REST API 以通过 curl 传输获取 json 文件。调用如下所示:

curl -k -s -X GET -H "Authorization: Bearer xyxyxyz" -H "Content-Type: application/json" \
    "https://code.somecompany.corp/bitbucket/rest/api"/1.0/projects/<projectname>/repos/davinci-reviewer-list/browse/mapfile.json --output mapfile.json

输出应该与 mapfile.json 的原始内容完全相同:

{
  "repos": [
    {
      "reponame": "account-opening-svc",
      "rev_list": "BE"
    },
    {
      "reponame": "alertmanager-config",
      "rev_list": "DEVOPS"
    },
    {
      "reponame": "antivirus-lambda",
      "rev_list": "BE"
    }
]
}

但是当我打开或 cat mapfile.json 时,字符串 'text' 和字符串 'lines' 已添加到每一行以及特殊字符:

{
    "lines": [
        {
            "text": "{"
        },
        {
            "text": "  \"repos\": ["
        },
        {
            "text": "    {"
        },
        {
            "text": "      \"reponame\": \"account-opening-svc\","
        },
        {
            "text": "      \"rev_list\": \"BE\""
        },
        {
            "text": "    },"
        },
        {
            "text": "    {"
        },
        {
            "text": "      \"reponame\": \"alertmanager-config\","
        },
        {
            "text": "      \"rev_list\": \"DEVOPS\""
        },
        {
            "text": "    },"
        },
        {
            "text": "    {"
        },
        {
            "text": "      \"reponame\": \"antivirus-lambda\","
        },
        {
            "text": "      \"rev_list\": \"BE\""
        },
        {
            "text": "    },"
        }...
        ],
    "start": 0,
    "size": 340,
    "isLastPage": true
}

我怎样才能得到原始的 json 内容?提前谢谢了!!!

标签: jsoncurl

解决方案


问题已解决 - url 仅指向 Bitbucket 的 api,但需要指向原始数据的链接。就我而言,它看起来像:

/rest/api/1.0/projects/<projectname>/repos/reviewer-list/raw/mapfile.json?at=refs%2Fheads%2Fmaster

推荐阅读