-1
I have that code:
public static void main(String[] args) throws JSONException {
String filmes[] = new String[2];
RestTemplate restTemplate = new RestTemplate();
String resposta = restTemplate.getForObject("https:api.....", String.class);
String resFormatada = resposta.replace("[","");
JSONObject jsonObject = new JSONObject(resFormatada);
for (int i = 0; i<3; i++) {
filmes[i] = jsonObject.getString("id");
System.out.println(filmes[i]);
}
}
The return of the api is:
[{"id":"tt3606756","titulo":"Os Incríveis 2","ano":2018,"nota":8.5},{"id":"tt4881806","titulo":"Jurassic World: Reino Ameaçado","ano":2018,"nota":6.7},{"id":"tt5164214","titulo":"Oito Mulheres e um Segredo","ano":2018,"nota":6.3}]
I would like to save each ID in a vector, but the way I do I’m only getting the first one and not all 3. Someone could help me.
Thank you, it worked!
– user167737