由於與我正在處理的項目有關的原因,我希望將整個查詢保存爲JSON文件作爲字符串,例如$.store.book[*].title
(而不是必須將文檔的每個級別臨時存儲爲一個單獨的對象)。JsonPath NoClassDefFoundError,或Java中JsonPath的替代者
我目前正在使用JsonPath(版本0.8.0,這是我能找到的最新版本),這基本上就是我在找的東西,但是我得到如下所示的異常。我只是使用JsonPath google代碼頁上給出的示例JSON,使用其示例查詢之一。
我在這裏做錯了什麼?或者,如果沒有解決方案,Java中是否有替代JsonPath的選擇?我希望能夠將整個查詢作爲字符串傳遞,並且必須使用Java。
功能:
public void testJsonPath() throws Exception
{
String query = "$.store.book[*].title";
List toRet = (List) JsonPath.read(practiceJson, query, new Filter[0]);
System.out.println(toRet.toString());
}
例外:
java.lang.NoClassDefFoundError: net/minidev/json/parser/ParseException
at com.jayway.jsonpath.spi.JsonProviderFactory$1.create(JsonProviderFactory.java:27)
at com.jayway.jsonpath.spi.JsonProviderFactory.createProvider(JsonProviderFactory.java:32)
at com.jayway.jsonpath.JsonPath.read(JsonPath.java:202)
at com.jayway.jsonpath.JsonPath.read(JsonPath.java:307)
at net.windward.datasource.test.TestJsonDataSource.testJsonPath(TestJsonDataSource.java:119)
實踐JSON:
private String practiceJson = "{\n" +
" \"store\": {\n" +
" \"book\": [ {\n" +
" \"category\": \"reference\",\n" +
" \"author\": \"Nigel Rees\",\n" +
" \"title\": \"Sayings of the Century\",\n" +
" \"price\": 8.95\n" +
" }, {\n" +
" \"category\": \"fiction\",\n" +
" \"author\": \"Evelyn Waugh\",\n" +
" \"title\": \"Sword of Honour\",\n" +
" \"price\": 12.99\n" +
" }, {\n" +
" \"category\": \"fiction\",\n" +
" \"author\": \"Herman Melville\",\n" +
" \"title\": \"Moby Dick\",\n" +
" \"isbn\": \"0-553-21311-3\",\n" +
" \"price\": 8.99\n" +
" }, {\n" +
" \"category\": \"fiction\",\n" +
" \"author\": \"J. R. R. Tolkien\",\n" +
" \"title\": \"The Lord of the Rings\",\n" +
" \"isbn\": \"0-395-19395-8\",\n" +
" \"price\": 22.99\n" +
" } ],\n" +
" \"bicycle\": [ {\n" +
" \"color\": \"red\",\n" +
" \"price\": 19.95,\n" +
" \"style\": [ \"city\", \"hybrid\" ]\n" +
" }, {\n" +
" \"color\": \"blue\",\n" +
" \"price\": 59.91,\n" +
" \"style\": [ \"downhill\", \"freeride\" ]\n" +
" } ]\n" +
" }\n" +
"}";
啊哈,就是這樣!非常感謝你! – firechant
謝謝您的電腦:D – cegprakash
謝謝,它添加所有依賴關係後爲我工作。 – Ravikumar11