我这周开始学习 ClojureScript,我一直在解析 Transit 响应,我有这个功能:
(defn handler [response]
(let [comment (:comment response)
created_at (:created_at response)
last_name (:last_name response)
_ (.log js/console (str ">>> COMMENT >>>>> " comment))
comments_div (.getElementById js/document "comments")]
(.append comments_div comment)
(.log js/console (str "Handler response: " response))))
控制台显示:
因此,“响应”看起来不错,但我无法使用以下方法从“响应”地图(我认为是地图)中获取内容:
comment (:comment response) or comment (get response :comment)
标头说响应是“应用程序/传输+json”类型。我试过:
(ns blog.core
(:require [cognitect.transit :as t]))
(def r (t/reader :json))
let [parsed (t/read r response).... <--- inside the let block
但到目前为止还没有运气。需要我解析变量“响应”吗?