在Clojure中使用JSON - 未定义的错误

问题描述 投票:1回答:1

您好我正在尝试使用Clojure从网站解析JSON,我已经读过我需要包含该行

(require '[clojure.data.json :as json])

在我的程序中使用JSON。但是每当我运行此行时,我都会收到此错误

enter image description here

我不知道为什么它不起作用或者是否还有其他东西需要包括才能使它工作?我打算使用slurp来使用JSON文件并解析它,但是如果没有这个要求就不能这样做(据我所知)

有任何想法吗?

(我使用带有Clojure扩展的Visual Studio代码和.lein repl来运行它)

json clojure visual-studio-code
1个回答
0
投票

它可能是您的IDE中的错误消息。

尝试创建一个新的目录demo喜欢

~ > mkdir tmp-0729
~ > cd tmp-0729
~/tmp-0729 > lein new app demo
Generating a project called demo based on the 'app' template.
~/tmp-0729 > cd demo

   <add a line to project.clj in editor>

~/tmp-0729/demo > cat project.clj 
(defproject demo "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [
                 [org.clojure/clojure "1.8.0"]
                 [org.clojure/data.json "0.2.6"]
  ]
  :main ^:skip-aot demo.core
  :target-path "target/%s"
  :profiles {:uberjar {:aot :all}})

确保你对org.clojure/data.json中的project.clj有额外的要求。然后你的代码应该工作:

~/tmp-0729/demo > lein repl      
nREPL server started on port 40638 on host 127.0.0.1 - nrepl://127.0.0.1:40638
REPL-y 0.3.7, nREPL 0.2.12
Clojure 1.8.0
Java HotSpot(TM) 64-Bit Server VM 1.8.0_144-b01
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
    Exit: Control+D or (exit) or (quit)
 Results: Stored in vars *1, *2, *3, an exception in *e

demo.core=> (require '[clojure.data.json :as json])
nil
demo.core=> (json/write-str {:a 1 :b 2})
"{\"a\":1,\"b\":2}"
demo.core=> (json/read-str "{\"a\":1,\"b\":2}")
{"a" 1, "b" 2}
demo.core=> 
© www.soinside.com 2019 - 2024. All rights reserved.