0

I get the error message string(ex.getMessage()) from Throwable in Android like below

{"message":"Authorization has been denied for this request."}

What is the best way to get only the message part from this error message string?

user689072
  • 134
  • 8

1 Answers1

0

Use JSON parser like Gson and create class ErrorMessage like this

public class ErrorMessage{

private String message;

public getMessage(){
    return message;
    }
}

Then you just parse it using Gson:

Gson gson = new Gson(); String error = gson.fromJson(jsonString, ErrorMessage.class);

Jacek
  • 63
  • 8