【问题标题】:JSON parsing issue in Android using json simpleAndroid中使用json简单的JSON解析问题
【发布时间】:2016-01-28 05:39:08
【问题描述】:

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

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

发生错误:

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

请提出一种方法。提前致谢。

【问题讨论】:

  • 考虑使用预构建的 Java JSON 库 - json-simple 已在一年前的最后一次更新中存档。你导入了org.json.JSONArray;org.json.JSONObject; 吗?
  • org.json.JSONArray 和 org.json.JSONObject 还有一些其他问题。这就是我开始使用 json-simple 的原因。但是在android中,当我使用JSONParser时,会出现错误。

标签: android json-simple


【解决方案1】:

看起来你错过了在你的类路径中包含filename.jar。包括相同的,它应该得到解决。

希望这会有所帮助!

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

    • 我使用 ADT(Eclipse 版本)
    【解决方案3】:

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

    在eclipse中右键项目-> Buildpath -> Configure Build path -> Java Build Path (left Pane) -> Libraries(Tab) -> Add External Jars -> Select your jar and select ok.

    但它没有用。 google了很多,我发现,添加jar文件后,选择“Order and Export”选项卡,然后查看当前添加的外部文件,最后刷新项目。然后它将完美运行。

    参考这个问题:How can I resolve this java.lang.NoClassDefFoundError: org.json.simple.JSONObject error? 在这个问题中,我们找不到答案,但正确的答案已添加为评论。感谢@peeskillet添加评论。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多