简体   繁体   中英

JSON parsing issue in Android using json simple

As i have some issues while working with Android's JSON (ie org.json), so here i'm using json simple . But when i try to convert string into json object using json parser, such as,

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

an error occur :

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

Please suggest a method. Thanks in advance.

From my experience, even if we add the respective jar file, it wont work properly. For adding an external jar file, i followed the steps below:

Right click on project in eclipse -> Buildpath -> Configure Build path -> Java Build Path (left Pane) -> Libraries(Tab) -> Add External Jars -> Select your jar and select ok.

But it didn't work. After googling a lot, i found that, after adding the jar file, select the "Order and Export" tab, then check the currently added external file, finally refresh the project. Then it will work perfectly.

Refer this question: 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 for adding the comment.

Looks like you have missed including the filename.jar in your classpath. Include the same and it should get solved.

Hope this helps !

If there's problem with import .jar try something else.

Do you use gradle? If yes import in dependencies this line: compile 'com.googlecode.json-simple:json-simple:1.1'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM