This week's book / license giveaways are in the JDBC and Relational Databases and Java in General forums.
We're giving away four copies each of PostGIS in Action and Java Advanced Topics Training and have the authors on-line!
See this thread and this one for details.
The moose likes Other Open Source Projects and the fly likes get the result of a URL query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "get the result of a URL query" Watch "get the result of a URL query" New topic
Author

get the result of a URL query

Sukhwinder Brar
Greenhorn

Joined: Feb 05, 2013
Posts: 1
Hi! I am developing a weather forecast application which uses OpenWeatherMaps API to find the forecasts for next seven days for a city. I am new to API as well as JSON. So, I have used the API as following:

public void findWeather(String city){

try {
URL myURL = new URL("http://api.openweathermap.org/data/2.1/forecast/city?q=" + city);
System.out.print(myURL.getContent());
URLConnection myURLConnection = myURL.openConnection();
myURLConnection.connect();
}

catch (MalformedURLException e) {
JOptionPane.showMessageDialog(null, e);
}
catch (IOException e) {
JOptionPane.showMessageDialog(null, e);
}
}
}

Now, if you try to copy the URL and paste it in your browser while replacing city by any city name, you get the result but they are in JSON I think. All I want is to parse that result into a table or list which I can display on my GUI.

Any kind of help is appreciated..
Paul Clapham
Sheriff

Joined: Oct 14, 2005
Posts: 19434
    
  10

Yes, that's JSON. (I tried your URL with my city at the end and got a lot of JSON in my browser.)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: get the result of a URL query