Search code examples
javaandroidjsonandroid-studioretrofit

How to write a model class for json string response in retrofit?


Hi I am new to android,

I have worked with regular json object response but now I have been asked to work with json string response like this,

"{\"message\":\"OTP is sent to your Mobile number and Email id\",\"status\":true,\"existing_user\":true}"

I have no idea how to call API's with this response. I searched how to do it and found nothing. Please help me if anyone knows how to get it done. Thanks in advance!


Solution

  • First, for network calls you can use Retrofit.

    Then you can convert your JSON response to java class with this site Json to java

    For example, your JSON is converted to the below class

    public class Output{
    
    public String message;
    public Boolean status;
    public Boolean existingUser;
    
    }