I'm making a Java application for school in which I want to fetch data from an API in JSON format. More precisely, I fetch a list of objects. Each object contains data about one thing, let's say movie data.
The returned data looks like this: {"page":1,"total_results":102,"total_pages":6,"results":[{"vote_count":13240,"id":597,"video":false,"vote_average":7.8,"title":"Titanic"}]}
.
Now, for each row of movies in "results", I want to show the name in a JTable
. Right now the code looks like:
String text = searchField.getText();
String url = "https://api.themoviedb.org/3/search/movie?api_key=SECRET&query=" + URLEncoder.encode(text, "UTF-8");
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer buffer = new StringBuffer();
while((inputLine = in.readLine()) != null)
{
buffer.append(inputLine);
}
in.close();
DefaultTableModel table = new DefaultTableModel();
table.addColumn("Title");
jTable.setModel(table);
Now I'm a bit stuck. Where do I go from here?