stringify/parse edn in clojure/ClojureScript

与世无争的帅哥 提交于 2019-12-12 11:49:56

问题


In JavaScript one can turn a js data structure into a JSON string via

JSON.stringify({somedata: { somesubdata: {}}})

And somewhere else, one can parse it again into a JS data structure via

var my_obj = JSON.parse("{"somedata":{"some_subdata":{}}}");

What would be the equivalent in Clojure/ClojureScript for the edn format?

I want to stringify some data on a ClojureScript front-end and parse it on a Clojure back-end. (and vice versa)


回答1:


As pointed out in a comment, a very detailed answer to this question can be found at the referenced link above.

After reading this, a quick answer, maybe especailly for people coming from JavaScript, would be:

in Clojure:

parse: clojure.edn/read-string
stringify: prn-str

in ClojureScript:

parse: cljs.reader/read-string
stringify: prn-str


来源:https://stackoverflow.com/questions/36208287/stringify-parse-edn-in-clojure-clojurescript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!