JsonPath NoClassDefFoundError,或Java中JsonPath的替代方法 [英] JsonPath NoClassDefFoundError, or an alternative to JsonPath in Java

查看:172
本文介绍了JsonPath NoClassDefFoundError,或Java中JsonPath的替代方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于与我正在从事的项目有关的原因,我希望将对JSON文件的整个查询保存为字符串,例如$.store.book[*].title(而不必存储文档的每个级别)暂时作为一个单独的对象.

For reasons related to the project I'm working on, I'd like an entire query to a JSON file to be held as a string, for example, $.store.book[*].title (rather than having to store each level of the document temporarily as a separate object).

我目前正在使用JsonPath(版本0.8.0,这是我能找到的最新版本),基本上这正是我在寻找的东西,但是我遇到了如下所示的异常.我只是使用JsonPath Google代码页上提供的示例JSON,并使用其中的一个示例查询.

I'm currently using JsonPath (version 0.8.0, which was the latest I could find), which is basically exactly what I'm looking for, but I'm getting the exception shown below. I'm just using the sample JSON given on the JsonPath google code page, using one of their sample queries.

我在这里做错了什么?或者,如果没有解决方案,Java中是否可以替代JsonPath?我希望能够将整个查询作为字符串传递,并且必须使用Java.

What am I doing wrong here? Alternatively, if there's not a solution, are there alternatives to JsonPath in Java? I want to be able to pass an entire query as a string, and it must be in 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" +
        "}";

推荐答案

我认为您必须将以下依赖项添加到项目中:

I think you have to add these dependencies to your project: https://code.google.com/p/json-path/downloads/detail?name=json-path-0.8.0-dependencies.zip&can=2&q=

特别是其中包含缺少的Exception类的json-smart-1.1.jar.

In particular json-smart-1.1.jar where the missing Exception class is contained.

这篇关于JsonPath NoClassDefFoundError,或Java中JsonPath的替代方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆