0

I want show message from server into my application, and i should show this message from json.
But message text such as this : &#274 4;&#276 5;&#272 5;&#273 9;

I use this code for show message text from json :

public void onResponse(Call<ServerResponse> call, Response<ServerResponse> response) {

    ServerResponse resp = response.body();

    if (resp.getResult().equals("success")) {
        Snackbar.make(getView(), reps.getMessage(), Snackbar.LENGTH_LONG).show();

but show &#274 4;&#276 5;&#272 5;&#273 9; in Snackbar!!

how can i fix it?

Bertrand Martel
  • 42,756
  • 16
  • 135
  • 159

2 Answers2

1

You have to unscape character before display string. You can read this.

Just to summarize. I suggest you to include in your project the jar commons-lang of Apache foundation in compile dependencies:

compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.0'

and then modify your code in this way:

import org.apache.commons.lang3.StringEscapeUtils;

...

public void onResponse(Call<ServerResponse> call, Response<ServerResponse> response) {
  ServerResponse resp = response.body();
  if (resp.getResult().equals("success")) {
    Snackbar.make(getView(), StringEscapeUtils.unescapeHtml4(reps.getMessage()), Snackbar.LENGTH_LONG).show();
Community
  • 1
  • 1
xcesco
  • 4,690
  • 4
  • 34
  • 65
0

You can try and create a new String object out of the response message.

String value = new String(reps.getMessage().getBytes("UTF-8"));

assuming that 'reps.getMessage()' returns String

MarkySmarky
  • 1,609
  • 14
  • 17
  • show me this error : `Cannot resolve constructor 'String(java.langString, java.lang.String)'` how can i fix it? –  Mar 13 '17 at 10:47
  • can you help me? pleaseeee i need this help –  Mar 13 '17 at 10:49