JSON Android 中使用 json 简单的解析问题

JSON parsing issue in Android using json simple

因为我在使用 Android 的 JSON(即 org.json)时遇到一些问题,所以这里我使用 json simple。但是当我尝试使用 json 解析器将字符串转换为 json 对象时,例如

JSONObject masterJson = (JSONObject) new JSONParser().parse(stringdata);

发生错误:

java.lang.NoClassDefFoundError: org.json.simple.JSONObject

请推荐一个方法。提前致谢。

您似乎没有在类路径中包含 filename.jar。包括相同的,它应该得到解决。

希望对您有所帮助!

如果导入 .jar 有问题,请尝试其他方法。

你用gradle吗?如果是,请在 dependencies 中导入此行:compile 'com.googlecode.json-simple:json-simple:1.1'

根据我的经验,即使我们添加相应的 jar 文件,它也无法正常工作。为了添加外部 jar 文件,我按照以下步骤操作:

右键单击 eclipse 中的项目 -> 构建路径 -> 配置构建路径 -> Java 构建路径(左窗格) -> 库(选项卡) -> 添加外部 Jars -> Select你的罐子 select 好的。

但是没有用。 google了很多,发现添加jar文件后,select"Order and Export"选项卡,然后查看当前添加的外部文件,最后刷新项目。然后就可以完美运行了。

参考这个问题:How can I resolve this java.lang.NoClassDefFoundError: org.json.simple.JSONObject error? In this question, we cant find an answere, but the correct answere was added as a comment. Thanks to @peeskillet 添加评论。