我正在尝试在Clojure中使用https://github.com/json-path/JsonPath
从自述文件看,它看起来很简单,特别是因为它使用了静态函数。所以我从自述中复制了这个例子:
(import '[com.jayway.jsonpath JsonPath Criteria Filter])
(JsonPath/parse "{\"a\":\"1\"}") ;; returns a com.jayway.jsonpath.internal.JsonContext
(JsonPath/read (JsonPath/parse "{\"a\":\"1\"}") "$.a")
;; (.read (JsonPath/parse "{\"a\":\"1\"}") "$.a")
;; Exception ->
;; 1. Caused by java.lang.IllegalArgumentException
;; No matching method: read
;; I tried variations of the above line
;; for some reason this seems to want to take `this` as first parameter - I cannot
;; figure out why, and cannot seem to be able to pass a valid value如何从Clojure调用这个Java静态函数?它为什么要作为this
依赖关系:[com.jayway.jsonpath/json-path "2.4.0"]
发布于 2018-07-31 15:40:41
问题是在Predicate上使用read的varargs。在JVM级别上,必须将那些args作为数组传递。使用Java,编译器将处理这个问题。
例如,这项工作:
user=> (import '[com.jayway.jsonpath JsonPath Criteria Filter Predicate])
#<Class@5a114a96 com.jayway.jsonpath.Predicate>
user=> (JsonPath/read "{\"a\":\"1\"}" "$.a" (into-array Predicate []))
"1"https://stackoverflow.com/questions/51616583
复制相似问题