Convert an Object List to UTF-8 in java

Asked

Viewed 99 times

1

I’m making a system Using java jsp, using webservice Restful, where I just consume data from a webservice through a link. Then on the main page, I create a list of objects coming from webservice, I use Google gson to generate my object list. The problem is that after generating this list, I have the accent problem in the words of this list of objects.

I wonder how I can convert this list so that the accents are correct?

<%
  HttpExemplo teste = new HttpExemplo();
  String json = teste.sendGet();
  final Gson gson = new Gson();

  List<Cidade> cidade = gson.fromJson(json, List.class);
  if (tes != null) {
    Cidade city = new Cidade(tes);
    if (cidade.contains(city)) {
      city = cidade.get(cidade.indexOf(city));
    }
    out.println(city.getEstado());
  }
%>
  • Please post the class code HttpExemplo.

  • You can try the following: String json = test.sendGet(); String jsonUTF8 = new String(json.getBytes(), Charset.forName("UTF-8"));

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.