我的应用程序的入口点从stdin读取,调用逻辑层来处理输入,并以JSON字符串的形式返回输出(使用cheshire库)。
但目前,我的输出是JSON的向量,如下所示:
[{"person":{"active":true,"age":41}},{"person":{"active":false,"age": 39}}]我需要在控制台的单独一行中打印每个JSON,如下所示:
{"person": {"active": true, "age": 41}}
{"person": {"active": false, "age": 39}}这是我当前的代码:
(defn read-input! [file]
(with-open [r (io/reader file)]
(doall (map #(cheshire/parse-string % true)
(line-seq r)))))
(defn input-received [input]
(map logic/process-input input))
(defn -main
[& args]
(println (cheshire/generate-string (-> args first read-input! input-received))))我试过做(apply println (cheshire/generate-string (-> args first read-input! input-received)))。但是每个字符都被打印到每一行。
发布于 2021-09-01 09:14:27
不是将整个输出向量打印为一个JSON字符串,而是单独打印向量的每个元素:
(defn print-all [xs]
(dorun (map (comp println cheshire/generate-string) xs)))(print-all [{"person" {"active" true "age" 41}} {"person" {"active" false "age" 39}}])
;; prints the following:
{"person":{"active":true,"age":41}}
{"person":{"active":false,"age":39}}https://stackoverflow.com/questions/69001326
复制相似问题