用Clojure从本地文件中读取JSON?
我很清楚如何从HTTP请求中解析JSON。但是我想在我的代码中使用一个JSON文件。
我试图在Google上找到解决方案,但我正在努力弄清楚如何从文件系统中读取本地JSON文件,
谢谢
Vinn
Im pretty clear on how to parse JSON from http requests. But I have a JSON file locally I would like to use within my code.
I have tried to find a solution on google but I am struggling to figure out how to read a local JSON file from the file system
Thanks
Vinn
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 clojure/data.json 库:
project.clj :
[org.clojure/data.json“ 2.4.0”]
(:quare clojure.data.json.json:as json]))
read-str> read-str >
使用
slurp
。我用此内容制作了示例文件
fileName.json
:并以此方式阅读:
Use clojure/data.json library:
project.clj
:[org.clojure/data.json "2.4.0"]
(:require [clojure.data.json :as json])
read-str
withslurp
. I made example filefilename.json
with this content:and read it like this:
在Clojure中,您可以使用DEP:
导入类:
并使用此功能并返回MAPP
In clojure you can use the dep:
import the class:
and use this function and return you a mapp
好吧,从HTTP请求到达的JSON和从本地文件到达的JSON有什么区别?我想真正的问题是“如何从本地文件中读取”,不是吗?
https://github.com/clojure/data.json”从字符串中读取JSON的方法
这是如何使用
,让我们从文件中读取它:
确保它们相同:
它将打印“相同”和解析的JSON值。
Well, what's the difference between a json arriving from an http request and a json arriving from a local file? I suppose the real question then is "how to read from a local file", no?
Here is how to read a json from a string using clojure/data.json:
Now, lets put the same string into a file
And lets read it from the file:
Make sure they are the same:
Which would print "same" and the parsed json value.