JSON解析引发错误 [英] JSON parsing throws error

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

问题描述

Stackoverflow中有很多示例来展示如何解析JSON.但是没有一个例子对我有用,我想我有一个普遍的问题,我不明白:

There are a lot of example in Stackoverflow to show howto parse JSON. But no example worked for me and I guess I have a general issue, which I do not understand:

我在以下陈述中得到一个错误:

I get an error at following statement:

JSONObject obj2 = new JSONObject("{interests : [{interestKey:Dogs}, {interestKey:Cats}]}");

例外:

Exception in thread "main" java.lang.RuntimeException: Stub!
    at org.json.JSONObject.<init>(JSONObject.java:7)
    at JSONTest.main(JSONTest.java:44)

我正在使用Java 1.7和库org.json

I am using Java 1.7 and the library org.json

我尝试了以下示例: 示例1 示例2

I tried examples like: example 1 example 2

可能是什么原因?

推荐答案

问题是项目的类路径中有android.jar.如果您正在编写Android应用,则必须必须在模拟器或实际设备上运行它. (这也意味着您将需要一个Activity而不是main(),并且还学习了Android应用程序的基本构建块.)否则,您应该从项目的类路径中删除所有与Android相关的内容,并改用标准Java SDK.清理问题的最简单方法是创建一个全新的Java(非Android)项目.

The problem is that you have android.jar in your project's classpath. If you are writing an Android app, you must run it in an emulator or on an actual device. (This also means you will need an Activity instead of main() and also learn the basic building blocks of an Android app.) Otherwise, you should remove anything related to Android from your project's classpath and use the standard Java SDK instead. The easiest way to clean things up is to create a brand-new Java (non-Android) project.

这篇关于JSON解析引发错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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