• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

get the result of a URL query

 
Sukhwinder Brar
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that's JSON. (I tried your URL with my city at the end and got a lot of JSON in my browser.)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic