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?

2
  • get me the json response Commented Mar 13, 2017 at 10:39
  • @VinayJayaram, Server or Android ? Commented Mar 13, 2017 at 10:44

2 Answers 2

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();
Sign up to request clarification or add additional context in comments.

1 Comment

Thnx my frieeeeeeeeeeeeeend. thnx <3
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

2 Comments

show me this error : Cannot resolve constructor 'String(java.langString, java.lang.String)' how can i fix it?
can you help me? pleaseeee i need this help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.