gpt4 book ai didi

json - clj-http/获取网址 { :as :json} doesn't work in script but in REPL

转载 作者:行者123 更新时间:2023-12-02 09:31:57 24 4
gpt4 key购买 nike

我正在尝试 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 2.0.0 版发生了重大变化。现在必须在 project.clj 中显式列出可选依赖项。添加后

[cheshire "5.5.0"]

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

关于json - clj-http/获取网址 { :as :json} doesn't work in script but in REPL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32131712/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com