2
I’m having some doubts, as I do to parse a JSON that is coming from the webservice.
My class comentarios
is like this:
public class Comentarios extends BaseEntity {
private Integer avaliacao;
private String observacaoAvaliacao;
private String nmCliente;
public Comentarios(Integer avaliacao, String observacaoAvaliacao, String nmCliente) {
avaliacao = avaliacao;
observacaoAvaliacao = observacaoAvaliacao;
nmCliente = nmCliente;
}
public void setAvaliacao(Integer avaliacao) {
this.avaliacao = avaliacao;
}
public void setObservacaoAvaliacao(String observacaoAvaliacao) {
this.observacaoAvaliacao = observacaoAvaliacao;
}
public void setNmCliente(String nmCliente) {
this.nmCliente = nmCliente;
}
public Integer getAvaliacao() {
return avaliacao;
}
public String getObservacaoAvaliacao() {
return observacaoAvaliacao;
}
public String getNmCliente() {
return nmCliente;
}
}
My JSON is coming from the server like this:
Resposta: {
"sucesso": true,
"mensagem": " Comentarios listados com sucesso. ",
“comentarios”:[
{
“avaliacao”:”4”,
“observacaoAvaliacao”:”Restaurante muito bom, valeu a pena comer o crepe de frango, e muito melhor é o aplicativo.”,
“nmCliente”:”Renan R.”
}
]
}
I need access like this:
Comentarios comentarios;
comentarios.getNmCliente();
There are many comments, you can make an example for an array of objects ?
– Renan Rodrigues
To convert JSON to a Java object (POJO) I suggest Google’s Gson library.
– Piovezan
@Piovezan would like to add an answer with his tip, I think it validates, even if I have already accepted the previous, due to new technologies
– Renan Rodrigues
@Renanrodrigues Just add, you can change the accepted answer after you have already accepted.
– Piovezan
It is worthwhile then you indicate something better, has as ?
– Renan Rodrigues
@Renanrodrigues did not understand your question. I have indicated something better, which is the Google Gson library.
– Piovezan