Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
456 views
in Technique[技术] by (71.8m points)

java - JSON parsing throws error

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:

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

I am using Java 1.7 and the library org.json

I tried examples like: example 1 example 2

What could be the reason ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...