我有一段时间没有写Clojure程序了,所以有点生疏。
基本上,我正在尝试编写代码,对REST API执行HTTP GET请求,然后将该JSON对象数组转换为Clojure数据(Map列表?)。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
你知道我做错了什么吗?