0
I’m trying this error because I’m picking up (from an api) a json, does anyone help me how to solve? I’m a beginner in JSF. This is my code to retrieve the data
@Named
@ViewScoped
public class DatasMBean implements Serializable {
private datas datas;
private String dados;
private String estado;
public datas getDatas() {
return datas;
}
public void setDatas(datas datas) {
this.datas = datas;
}
public String getEstado() {
return estado;
}
public void setEstado(String estado) {
this.estado = estado;
}
public void buscarDatas(){
String URL = "https://api.calendario.com.br/?json=true&ano=2019&estado=SC&cidade=JARAGUA_DO_SUL&token=ZmVsaXBlLm1vdGFlZmZ0aW5nQGdtYWlsLmNvbSZoYXNoPTE0NDA1Nzc2MA";
Client client = ClientBuilder.newClient();
WebTarget target = client.target(URL);
Response response = target.request().get();
//String json = response.readEntity(String.class);
String json = response.readEntity(String.class);
response.close();
datas = new Gson().fromJson(json, datas.class);
System.out.println(datas);
}
}
Here is the code of my class that would like to save the api data.
public class datas {
private String[] date;
private String[] name;
private String[] type;
private String[] description;
public String[] getDate() {
return date;
}
public void setDate(String[] date) {
this.date = date;
}
public String[] getName() {
return name;
}
public void setName(String[] name) {
this.name = name;
}
public String[] getType() {
return type;
}
public void setType(String[] type) {
this.type = type;
}
public String[] getDescription() {
return description;
}
public void setDescription(String[] description) {
this.description = description;
}
The error I get is this: Expected BEGIN_OBJECT but was BEGIN_ARRAY The json I’m trying to catch is here: https://api.calendario.com.br/? json=true&ano=2017&estado=Sp&cidade=SAO_PAULO&token=Zmvsaxbllm1vdgflzmz0aw5nqgdtywlslmnvbszoyxnopte0nda1nzc2ma