问题描述:

My plan is to make a JSON results by my database. What I mean is that I have made a Class where I connect to a API (etc. TMDB) and take the information I need.

public class MovieDataBase {

Attributes att = new Attributes(); //A klass where I have setter-getter

//methods for titel, overview, vote, release.

public String searchMovie(String filmtitel) {

HttpResponse<JsonNode> response;

try {

response = Unirest.get("http://api.themoviedb.org/3/search/movie")

.queryString("api_key", "123")

.queryString("query", filmtitel)

.asJson();

JsonNode json = response.getBody();

JSONObject envelope = json.getObject();

JSONArray results = envelope.getJSONArray("results");

filmtitel += att.title = results.getJSONObject(0).getString("title");

filmtitel += att.release = results.getJSONObject(0).getString("release_date");

filmtitel += att.vote = results.getJSONObject(0).getInt("vote_average");

filmtitel += att.overview = results.getJSONObject(0).getString("overview");

return filmtitel

}

catch (JSONException e) {

and I also have a get method where I want to create a JSON construction of the program to easier use it in the future (for html)

public static void main(String[] args) {

Gson gson = new Gson();

setPort(8080);

Youtube yt = new Youtube();

MovieDataBase mdb = new MovieDataBase();

get("/search/:movie", (req, res) -> {

String movie = req.queryParams(":movie");

String movies = mdb.searchMovie(movie);

String json = att.title + att.release + att.vote + att.vote + att.overview

json = gson.toJson(json);

return json

});

This did not work. I'm getting a null when I'm running it, not a error but only a null. So I have to combine String movies = mdb.searchMovie(movie); with the String Json and then make it look like a json, but I don't know if that's right.

相关阅读:
Top