我有一段时间没有写Clojure代码了,所以对我来说有点生疏。
基本上,我正在尝试编写一段代码,该代码执行REST API的HTTP GET操作并将JSON数组的对象转换为Clojure数据(列表映射?)。该JSON数据看起来像这样:
[
{
"id": 1,
"category": "technical",
"asin": "0131103628",
"title": "C Programming Language, 2nd Edition",
"publication_date": "1988-04-01T00:00:00Z",
"review": "The C book.",
"created_at": "2020-03-06T20:48:00Z"
},
{
"id": 2,
"category": "technical",
"asin": "0387966080",
"title": "The Science of Fractal Images",
"publication_date": "1988-07-19T00:00:00Z",
"review": "The book on fractal algorithms. Sadly, no longer in print. I had to search high and low for a used copied.",
"created_at": "2020-03-06T20:48:00Z"
},
// etc..
]
我使用http-kit(我也尝试过clj-http)调用REST API并返回响应体。稍后,我将响应体转换为Clojure数据。我尝试使用org.clojure/data.json和cheshire。然而,我认为数据转换并不正确。
(defn get-books-body
[]
(:body @(client/get books-url api-options)))
(defn get-books
[]
(parse-string get-books-body true))
当我尝试显示响应体的类型时,它显示为一个地址而不是字符串
clojure-json-test.core=> (type get-books-body)
clojure_json_test.core$get_books_body
而且,在从JSON转换后,我看不见第一条记录
clojure-json-test.core=> (first get-books)
Execution error (IllegalArgumentException) at clojure-json-test.core/eval3169 (form- init15378865171954877190.clj:1).
Don't know how to create ISeq from: clojure_json_test.core$get_books
你有什么建议吗?