我想转换 this example用于 Scala 的 JsonPath。使用 java 应该很容易,例如:
List<String> authors = JsonPath.read(json, "$.store.book[*].author");
val authors = JsonPath.read(json, "$.store.book[*].author");
ambiguous reference to overloaded definition, both method read in object JsonPath of type [T](x$1: String,
x$2: String, x$3: <repeated...>[com.jayway.jsonpath.Filter[_]])T and method read in object JsonPath of type
[T](x$1: Any, x$2: String, x$3: <repeated...>[com.jayway.jsonpath.Filter[_]])T match argument types
(String,String)
public static <T> T read(Object json, String jsonPath, Filter... filters)
public static <T> T read(String json, String jsonPath, Filter... filters)
最佳答案
对于这种特定情况,您可以这样做
JsonPath.read(json.asInstanceOf[Object], "$.store.book[*].author")
Object
的方法)。大概是该方法调用了 json.toString
这是微不足道的,因为我们已经有了 String
.
https://stackoverflow.com/questions/23331551/