4
我想從REST資源中使用clj-http版本2.2.0讀取JSON,但無論我做什麼,我都以字符串的形式得到結果。clj-http不返回JSON
調試時,我剝了下來我在做什麼這個請求對我的網絡服務器的靜態JSON文件上https://nym.at/test.json:
{"foo":1,"bar":"baz"}
我跑在REPL下面的代碼(client
綁定到命名空間CLJ-http.client):
(client/get "https://nym.at/test.json" {:as :json :insecure? true})
結果我得到的是(的pritty手動打印):
{:status 200,
:headers {"Server" "Apache/2.4.18 (Debian)",
"Upgrade" "h2,h2c",
"Content-Type" "application/json",
"Content-Length" "22",
"Strict-Transport-Security" "max-age=31536000; includeSubDomains",
"Connection" "Upgrade, close",
"Accept-Ranges" "bytes",
"ETag" "\"16-532fcf29f30c6\"",
"Date" "Mon, 16 May 2016 22:14:59 GMT",
"Last-Modified" "Mon, 16 May 2016 22:14:27 GMT"},
:body "{\"foo\":1,\"bar\":\"baz\"}\n",
:request-time 637,
:trace-redirects ["https://nym.at/test.json"],
:orig-content-encoding nil}
我的期望錯了,{:as :json}
應該導致clj-http將響應解析爲JSON,並在:body
上回應它,或者我在這裏做錯了什麼?
謝謝,這工作。我一定有錯誤的文檔,因爲我認爲柴郡是一個依賴,因此希望leiningen自動加載它。 –