Reputation:
I want show message from server into my application, and i should show this message from json
.
But message text such as this : Ē 4;Ĕ 5;Đ 5;đ 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 Ē 4;Ĕ 5;Đ 5;đ 9;
in Snackbar!!
how can i fix it?
Upvotes: 0
Views: 499
Reputation: 1629
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
Upvotes: 0
Reputation: 4838
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();
Upvotes: 1