java 使用jsonpath,在Java中使用JsonPath解析JSON

I am new to Json-Path.

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

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));

I am getting this error:

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

I have also inculded: org.apache.commons.lang-2.6.jar

But I am still getting the error. Am I missing something here ?

Found the problem:

I have to add following jar's to path:

json-path-0.8.0.jar

commons-lang-2.6.jar

commons-io-2.1.jar

json-smart-1.1.jar

I was missing the last 2.

解决方案

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...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值