У меня такой Json:
{
"hello": {
"hello": [
{
"wwrjgn": "aerg",
"aaa": "gggg",
"rfshs": {
"segse": "segsegs",
"xx": "rgwgwgw",
"x-e ": "eergye"
},
"egg": "sgsese",
"segess": "sgeses",
"segess": "segess"
},
{
"esges": "segesse",
"segesg": "ws",
"rddgdr": {
"rdrdrdg": “srgsesees"
},
"drr": 3600,
"esese": "uytk",
"wew": "699",
"eses": “qe4ty"
}
],
"how": www"
}
}
Я делаю следующее:
Object document =
Configuration.defaultConfiguration().addOptions().jsonProvider()
.parse(ka.toJSONString());
int queries = JsonPath.read(document, "$..hello.length()");
System.out.println("THE LENGTH OF THE NUMBER OF QUERIES " + queries);
Я получил:
nested exception is java.lang.ClassCastException: net.minidev.json.JSONArray
cannot be cast to java.base/java.lang.Integer] with root cause
java.lang.ClassCastException: net.minidev.json.JSONArray cannot be cast to
java.base/java.lang.Integer
Попробуйте здесь: http://jsonpath.herokuapp.com/?path= $ .. hello.length () я получаю:
[
2,
2
]
Это то, что мне нужно.
Есть идеи, что я делаю не так? Заранее спасибо.
JSONArray
(который, похоже, является результатом методаJsonPath.read(...)
) вInteger
. - person Turing85   schedule 06.04.2018JSONArray
класса. - person Turing85   schedule 06.04.2018