初学者 Clojurist 在这里。我正在尝试使用 Clojurescript 和cljs-http
库解析 JSON 文件。我使用以下函数有奇怪的行为:
(defn make-remote-call [endpoint]
(go (let [response (<! (http/get endpoint))]
(js/console.log (:body response)))))
这会将 json 文件打印到控制台,但我会收到以下错误消息:
XML Parsing Error: not well-formed
Location: file:///***U2328710-data.json
Line Number 1, Column 1:
我尝试过的事情:
- JSON 文件通过http://jsonlint.com成功,但https://jsonformatter.curiousconcept.com/解析文件并说
Error:Invalid encoding, expecting UTF-8, UTF-16 or UTF-32.[Code 29, Structure 0]
- 当我在 Apache 服务器上部署时出现同样的问题。我的 .htaccess 文件已正确设置为将 content-header 发送到 application/json 并将 charset 发送到 utf-8 (虽然我已经读过我应该发送大写的 UTF-8,但无法做到这一点)
- 我可以毫无问题地解析具有相同功能的 XML 文件
- 我可以使用已弃用的方法毫无问题地解析相同的 JSON 文件
js/XMLHttpRequest
没有想法了-有人可以帮忙吗?我想知道 cljs-http 是否不理解它是一个 json 文件,我可以强制它/也许覆盖标头吗?谢谢,