Reputation: 9936
I wrote a simple JsonParser code in java. I downloaded json jar file following this post. I included the jar file through,
Project Properties-> Java Build Path -> Libraries -> Add external jars
But still I get the error, "The import org.json.JSONObject cannot be resolved" for the import statements.
This is happening in my Ubuntu machine. But following the same steps, I am successfully able to include the jar and run my program in Windows. But I want it working in my Ubuntu machine. Should I do anything different ?
I have the jar file in the my project directory. It is also getting listed under Referenced Libraries in Package explorer.
[edit]: I did a ctrl + shift + O to organize imports in eclipse and the statements
import org.json.JSONObject
import org.json.JSONArray
import org.json.JSONExceptiop
got changed to,
import org.json.simple.JSONObject
import org.json.simple.JSONArray
with following error,
The constructor JSONArray(String) is undefined
The method length() is undefined for the type JSONArray
The method getJSONObject(int) is undefined for the type JSONArray
Upvotes: 3
Views: 5301
Reputation: 3567
Looks like you downloaded the .jar from here:
http://code.google.com/p/json-simple/
whereas the imports you had were based on the .jar from here:
http://www.java2s.com/Code/JarDownload/java/java-json.jar.zip
The JSONArray from json-simple does not have a constructor that takes a single string. Switch .jar files or fix the constructor.
Upvotes: 2