简体   繁体   English

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

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

I'm experimenting with Clojure and Leiningen. 我正在试验Clojure和Leiningen。 I was successful in executing to following line in the REPL: 我成功执行了REPL中的以下行:

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

I created a project with lein new http . 我用lein new http创建了一个项目。 When I run the following lines witn lein run then the coercion to JSON doesn't work. 当我运行以下行和lein run ,强制转换为JSON不起作用。 It simply prints a correct JSON string. 它只是打印正确的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}))

the output of the script is 脚本的输出是

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

Any idea what's wrong? 知道有什么问题吗?

As it turned out there was a breaking change with clj-http version 2.0.0. 事实证明,clj-http 2.0.0版发生了重大变化。 Now one has to list explicitly the optional dependencies in project.clj . 现在必须明确列出project.clj的可选依赖项。 After I added 在我添加之后

[cheshire "5.5.0"]

to my list of dependencies the program worked as expected. 在我的依赖项列表中,程序按预期工作。 Please see the documentation for the change here . 请在此处查看有关更改的文档。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM