在Java中使用JsonPath解析JSON [英] Parse JSON using JsonPath in Java

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

问题描述

我是Json-Path的新手.

I am new to Json-Path.

我在Eclipse构建路径中包含了json-path-0.8.0.jar.

I have included: json-path-0.8.0.jar in my eclipse build path.

我从以下位置复制了JSON: http://code.google.com/p/json-文件的路径/.

I copied JSON from: http://code.google.com/p/json-path/ to file.

我正在尝试解析此文件并使用以下方式显示作者姓名:

and I am trying to parse this file and display an authors name using:

String jsonPath = "$.store.book[1].author";

File jsonFile = new File("C:\\ServicesTest\\jsonresponse2.json");

System.out.println("Author: "+JsonPath.read(jsonFile, jsonPath));

我收到此错误:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang/Validate
at com.jayway.jsonpath.JsonPath.read(JsonPath.java:304)
at office.jsonPathparse.main(jsonPathparse.java:34)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.Validate
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more

我还灌输了:org.apache.commons.lang-2.6.jar 但是我仍然遇到错误.我在这里想念什么吗?

I have also inculded: org.apache.commons.lang-2.6.jar But I am still getting the error. Am I missing something here ?

发现了问题: 我必须在路径中添加以下jar:

Found the problem: I have to add following jar's to path:

json-path-0.8.0.jar

json-path-0.8.0.jar

commons-lang-2.6.jar

commons-lang-2.6.jar

commons-io-2.1.jar

commons-io-2.1.jar

json-smart-1.1.jar

json-smart-1.1.jar

我错过了最后2个.

推荐答案

您可能缺少导入语句,或者库jar文件实际上未正确添加到您的类路径中. NoClassDefFoundError表示Java找不到您的代码中引用的类...

You may be missing the import statements, or the library jar file is not actually added to your classpath correctly. NoClassDefFoundError means java can't find the class that is referenced in your code...

这篇关于在Java中使用JsonPath解析JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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