I use Eclipse.I am reading a url and retrieving a json string:
String message = "http://XXXXXXXXX";
try {
website = new URL(message);
URLConnection connection = website.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
str1 += inputLine;
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
try {
JSONObject jsono = new JSONObject(str1);
JSONObject results =jsono.getJSONObject("results");
JSONArray result =results.getJSONArray("result");
} catch(JSONException ex) {
System.out.println("Exception thrown: " + ex.getMessage());
}
And I can get it, I can print it out.
Then I wanna parse the json string using JSONArray and JSONObject, but there are errors in the three lines:
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
The error is : The import org.json cannot be resolved.
I am stuck here.
You need to include Json jar in your library .
Download the ZIP file from here and extract it to get the Jar. Add the Jar to your build path. To check the available classes in this Jar use this URL.
To Add this Jar to your build path
I hope this will solve your problem.