序列化字典

序列化 / 二进制格式

(require '[clojure.edn :as edn])

(def dic {1 "one" 2 "two"})

; 与 JSON 不同,EDN 会保留键的类型

; 编码二进制数据
(def data-b (.getBytes (pr-str dic) "UTF-8"))

; 解码二进制数据
(def dic2 (edn/read-string (String. data-b "UTF-8")))
; dic2 is {1 "one", 2 "two"}

(prn dic2)
(println "type is" (type dic2))