clj-http没有返回JSON

时间:2016-05-16 22:27:56

标签: json clojure clj-http

我正在尝试使用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处撤回,或者我在这里做错了什么?

1 个答案:

答案 0 :(得分:8)

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

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