6

我正在尝试使用 clj-http 版本 2.2.0 从 REST 资源中读取 JSON,但无论我做什么,我都会将结果作为字符串。

在调试时,我在https://nym.at/test.json上的网络服务器上将我对这个请求的操作剥离到一个静态 JSON 文档:

{"foo":1,"bar":"baz"}

我在 REPL 中运行以下代码(client绑定到命名空间 clj-http.client):

(client/get "https://nym.at/test.json" {:as :json :insecure? true})

我得到的结果是(手动打印):

{:status 200,
 :headers {"Server" "Apache/2.4.18 (Debian)",
           "Upgrade" "h2,h2c",
           "Content-Type" "application/json",
           "Content-Length" "22",
           "Strict-Transport-Security" "max-age=31536000; includeSubDomains",
           "Connection" "Upgrade, close",
           "Accept-Ranges" "bytes",
           "ETag" "\"16-532fcf29f30c6\"",
           "Date" "Mon, 16 May 2016 22:14:59 GMT",
           "Last-Modified" "Mon, 16 May 2016 22:14:27 GMT"},
 :body "{\"foo\":1,\"bar\":\"baz\"}\n",
 :request-time 637,
 :trace-redirects ["https://nym.at/test.json"],
 :orig-content-encoding nil}

我的期望是否错误,{:as :json}应该导致 clj-http 将响应解析为 JSON 并将其返回,:body或者我在这里做错了什么?

4

1 回答 1

9

添加[cheshire "5.6.1"]到您的项目中,它将神奇地开始工作

https://github.com/dakrone/clj-http#optional-dependencies

于 2016-05-16T22:50:25.610 回答