Showing posts with label Parsing Gson with SerializedName Class. Show all posts
Showing posts with label Parsing Gson with SerializedName Class. Show all posts

Wednesday 3 July 2019

Android Json response parsing method with Gson

Hello guy's here i  m sharing Json response parsing method to do parse in particular pojo class.
here you need to get your Json response in your String variable before start parsing it.


do this process in Your Class

String result = "Your Json Resonse" ;

List<MUsers> mUsers = null;
                try {
    Gson gson = new Gson();
    Type type = new TypeToken<List<MUsers>>(){}.getType();
    mUsers = gson.fromJson(result, type);
} catch (JsonSyntaxException e) {
    e.printStackTrace();
}

Here  in Your MUsers Class need to contain all require keys to parse it based on your Json response contains no of keys . here explaining with single key value parsing class as below it would be like.

public class MUsers{

    @SerializedName("USR")
    @Expose
    private String usr;

    public void setUSR(String usern) {
        this.usr = usern;
    }

    public String getUSR() {
        return usr;
    }
}



Here  in your build.gradle file need to add supportive library to parse this data

Find Hours Diffrence in Kotlin

  In Kotlin, determining the difference in hours between two timestamps is a common task, especially in scenarios involving time-based calcu...