curl后中文乱码?

"address":"����׳��������-������-������   

响应头是:

HTTP/1.1 200 OK
Server: 
Date: Fri, 11 Aug 2017 10:15:46 GMT
Content-Type: application/json;charset=GBK
Content-Length: 4534
Connection: keep-alive
Strict-Transport-Security: max-age=31536000
Content-Language: en-US
Via: 
Set-Cookie: 
阅读 24.4k
6 个回答

curl -H "charset=UTF-8"

在git bash上运行的curl,还是在服务器上?

Content-Type: application/json;charset=GBK

这是特殊的 JSON,属于中国特色。

如果你无法修正网站,那

curl .... | iconv -f gbk

转一下吧。

加上

|iconv -f gbk -t utf8
npm i -g json
C:\Users\v_jianjpeng>curl "http://www.pengjiandry.com:7080/api/v1/get/articles?page=1&pageSize=10&type=doing&keyword=&startDate=&endDate=" | json
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  3495  100  3495    0     0   3495      0  0:00:01 --:--:--  0:00:01 44807
{
  "data": {
    "total": 1,
    "pageSize": "10",
    "page": "1",
    "data": [
      {
        "_id": "5e5bbb19915c07ce2efc772c",
        "title": "centos7 安装使用 redis",
        "tag": [
          "Redis",
          "Centos7"
        ],
        "state": "doing",
        "content": "https://zhuanlan.zhihu.com/p/34527270\n```\nsudo yum -y install redis\n```\n\n```\nsudo systemctl start redis\n```\n\n```\nsudo systemctl restart redis\n```\n\n```\nvi /etc/redis.conf\n\n# bind 127.0.0.1\nrequirepass password\n```\n\n```\nsystemctl start redis.service #启动redis服务器\n\nsystemctl stop redis.service #停止redis服务器\n\nsystemctl restart redis.service #重新启动redis服务器\n\nsystemctl status redis.service #获取redis服务器的运行状态\n\nsystemctl enable redis.service #开机启动redis服务器\n\nsystemctl disable redis.service #开机禁用redis服务器\n```\n\n```\nsystemctl restart redis.service\n```",
        "createTime": "2020-03-02 15:06:19",
        "updateTime": "2020-03-02 15:17:04",
        "history": [
          {
            "_id": "5e5bbb19915c07ce2efc772c",
            "title": "centos 7 安装使用 redis",
            "tag": [
              "Mac"
            ],
            "content": "https://zhuanlan.zhihu.com/p/34527270\n```\nsudo yum -y install redis\n```\n\n```\nsudo systemctl start redis\n```\n\n```\nsudo systemctl restart redis\n```\n\n```\nvi /etc/redis.conf\n\n# bind 127.0.0.1\nrequirepass password\n```\n\n```\nsystemctl start redis.service #启动redis服务器\n\nsystemctl stop redis.service #停止redis服务器\n\nsystemctl restart redis.service #重新启动redis服务器\n\nsystemctl status redis.service #获取redis服务器的运行状态\n\nsystemctl enable redis.service #开机启动redis服务器\n\nsystemctl disable redis.service #开机禁用redis服务器\n```\n\n```\nsystemctl restart redis.service\n```",
            "createTime": "2020-03-01 21:39:37",
            "updateTime": "2020-03-01 21:39:37"
          },
          {
            "_id": "5e5bbb19915c07ce2efc772c",
            "title": "centos 7 安装使用 redis",
            "tag": [
              "Redis"
            ],
            "content": "https://zhuanlan.zhihu.com/p/34527270\n```\nsudo yum -y install redis\n```\n\n```\nsudo systemctl start redis\n```\n\n```\nsudo systemctl restart redis\n```\n\n```\nvi /etc/redis.conf\n\n# bind 127.0.0.1\nrequirepass password\n```\n\n```\nsystemctl start redis.service #启动redis服务器\n\nsystemctl stop redis.service #停止redis服务器\n\nsystemctl restart redis.service #重新启动redis服务器\n\nsystemctl status redis.service #获取redis服务器的运行状态\n\nsystemctl enable redis.service #开机启动redis服务器\n\nsystemctl disable redis.service #开机禁用redis服务器\n```\n\n```\nsystemctl restart redis.service\n```",
            "createTime": "2020-03-02 15:06:19",
            "updateTime": "2020-03-02 15:06:19",
            "version": 1
          },
          {
            "_id": "5e5bbb19915c07ce2efc772c",
            "title": "centos 7 安装使用 redis",
            "tag": [
              "Redis",
              "Centos7"
            ],
            "content": "https://zhuanlan.zhihu.com/p/34527270\n```\nsudo yum -y install redis\n```\n\n```\nsudo systemctl start redis\n```\n\n```\nsudo systemctl restart redis\n```\n\n```\nvi /etc/redis.conf\n\n# bind 127.0.0.1\nrequirepass password\n```\n\n```\nsystemctl start redis.service #启动redis服务器\n\nsystemctl stop redis.service #停止redis服务器\n\nsystemctl restart redis.service #重新启动redis服务器\n\nsystemctl status redis.service #获取redis服务器的运行状态\n\nsystemctl enable redis.service #开机启动redis服务器\n\nsystemctl disable redis.service #开机禁用redis服务器\n```\n\n```\nsystemctl restart redis.service\n```",
            "createTime": "2020-03-02 15:06:19",
            "updateTime": "2020-03-02 15:13:28",
            "version": "2"
          }
        ],
        "version": 3
      }
    ],
    "keyword": "",
    "type": "doing",
    "startDate": "",
    "endDate": ""
  }
}
新手上路,请多包涵

image.png
使用@方式,内容另写一个文件utf-8的。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏