0

How to get email or mobile from GET method in retrofit android

i'm trying more then time but my app crash so how to get these value.

JSON response.

{
    "statuscode": 200,
    "status": "true",
    "applied_jobs": [
        {
            "id": 1,
            "user_id": 44,
            "job_post_id": 12,
            "resume": "241115637974717139.doc",
            "created_at": "2019-07-22 12:11:11",
            "updated_at": "2019-07-22 12:11:11",
            "posted_job": {
                "id": 12,
                "user_id": 44,
                "email": "appt@gmail.com",
                "mobile": "9712112332",
                "company_name": "Appt Tech",
                "title": "Java Developer",
                "description": "Java, Android, XML",
                "no_of_position": 5,
                "job_requirment": "Experience",
                "country_id": 1,
                "state_id": 2,
                "city_id": 2,
                "location": "Noida",
                "photo": "242415637879146897.png",
                "status": 1,
                "created_at": "2019-07-22 09:31:54",
                "updated_at": "2019-07-22 09:31:54"
            }
        }

    ]
}

Retrofit Interface

    @GET("retrieve/get_applied_job?user_id=44")
    Call<ListAllAppliedJobs> getAllAppliedJobs();

I just want get email or mobile values

Jasurbek
  • 2,946
  • 3
  • 20
  • 37
Mr.JDroid
  • 1
  • 4

3 Answers3

0

http://www.jsonschema2pojo.org/ use this website to create model classes. Then use it for access email and mobile. If you are creating the api, then send only the required values.

Jude Osbert K
  • 940
  • 9
  • 22
  • Thanks but i want , how to get email mobile . like adapter or main activity with all files. Model i've already created but problem is that json parsing – Mr.JDroid Jul 25 '19 at 04:50
0

You have to convert your json response to a pojo class to retrieve the value, you can convert it using two ways :

  1. use http://www.jsonschema2pojo.org to convert directly
  2. Please refer How to convert JSON objects to POJO from Gson

and then retrieve the email from the email or the phone objects in the pojo class.

  • Thanks but i want , how to get email mobile . like adapter or main activity with all files. Model i've already created but problem is that json parsing – Mr.JDroid Jul 25 '19 at 04:50
0

@Jude Osbert k is Right

Place the below code it works http://www.jsonschema2pojo.org/ it works 100%

    import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class AppliedJob {


    @SerializedName("updated_at")
    @Expose
    private String updatedAt;
    @SerializedName("posted_job")
    @Expose
    private PostedJob postedJob;

    public String getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(String updatedAt) {
        this.updatedAt = updatedAt;
    }

    public PostedJob getPostedJob() {
        return postedJob;
    }

    public void setPostedJob(PostedJob postedJob) {
        this.postedJob = postedJob;
    }

}

import java.util.List;
        import com.google.gson.annotations.Expose;
        import com.google.gson.annotations.SerializedName;

public class ListAllAppliedJobs {

    @SerializedName("statuscode")
    @Expose
    private Integer statuscode;
    @SerializedName("status")
    @Expose
    private String status;
    @SerializedName("applied_jobs")
    @Expose
    private List<AppliedJob> appliedJobs = null;

    public Integer getStatuscode() {
        return statuscode;
    }

    public void setStatuscode(Integer statuscode) {
        this.statuscode = statuscode;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public List<AppliedJob> getAppliedJobs() {
        return appliedJobs;
    }

    public void setAppliedJobs(List<AppliedJob> appliedJobs) {
        this.appliedJobs = appliedJobs;
    }

}


import com.google.gson.annotations.Expose;
        import com.google.gson.annotations.SerializedName;

public class PostedJob {

    @SerializedName("id")
    @Expose
    private Integer id;
    @SerializedName("user_id")
    @Expose
    private Integer userId;
    @SerializedName("email")
    @Expose
    private String email;
    @SerializedName("mobile")
    @Expose
    private String mobile;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }


}
satyan_android
  • 364
  • 4
  • 15
  • Thanks but i want , how to get email mobile . like adapter or main activity with all files. Model i've already created but problem is that json parsing. – Mr.JDroid Jul 25 '19 at 04:49
  • List appliedJobs = response.body().getAppliedJobs(); for(int i= 0 ; i< appliedJobs.size(); i++){ appliedJobs.get(i).getPostedJob().getEmail(); } – satyan_android Jul 25 '19 at 04:56