clj-http/get url {:as :json} 在脚本中不起作用,但在 REPL 中不起作用

clj-http/get url {:as :json} doesn't work in script but in REPL

我正在试验 Clojure 和 Leiningen。 我成功地执行了 REPL 中的以下行:

(print (:body (client/get "https://coinbase.com/api/v1/prices/spot_rate?currency=CAD" {:as :json}))

我用 lein new http 创建了一个项目。当我 运行 以下几行和 lein run 时,对 JSON 的强制转换不起作用。它只是打印一个正确的 JSON 字符串。

(ns http.core
  (:require [clj-http.client :as client])
  (:use clojure.pprint))

(defn -main
  []
  (print
    (:body
      (client/get "https://coinbase.com/api/v1/prices/spot_rate?currency=CAD" {:as :json}))

脚本的输出是

{"amount":"306.89","currency":"CAD"}

知道哪里出了问题吗?

我不知道具体发生了什么变化,但 [clj-http "1.1.2"] 具有您想要的行为。

事实证明,clj-http 版本 2.0.0 发生了重大变化。 现在必须在 project.clj 中明确列出可选的依赖项。 添加后

[cheshire "5.5.0"]

在我的依赖项列表中,该程序按预期工作。 请参阅更改文档 here