Parse JSON array response using Retrofit & Gson

前端 未结 4 1666
青春惊慌失措
青春惊慌失措 2020-11-27 18:53

Here is my JSONArray Response from Web service:

[
  {
    "sponsors": [
      {
        "leg_id": "NYL000067",
        "typ         


        
4条回答
  •  甜味超标
    2020-11-27 19:30

    Please try to use this one

        @FormUrlEncoded
        @POST("api/sponsors")
        Call> getStatesAndDistrict(
                @Field("xyz") String field1
        );
    
    
    
       Call > call = service.getSponsorsValue();
    
        call.enqueue(new Callback>() {
            @Override
            public void onResponse(Call> call, Response> response) {
    
                List rs = response.body();
    
            }
    
            @Override
            public void onFailure(Call> call, Throwable t) {
    
            }
        });
    
    
    
     class SponsorsResult {
    
        @SerializedName("sponsors")
        private List sponsors;
    
        public List getSponsors() {
            return sponsors;
        }
    }
    
    class SponsorsValue{
        @SerializedName("leg_id")
        @Expose
        private String legId;
        @SerializedName("type")
        @Expose
        private String type;
        @SerializedName("name")
        @Expose
        private String name;
    
        public String getLegId() {
            return legId;
        }
    
        public void setLegId(String legId) {
            this.legId = legId;
        }
    
        public String getType() {
            return type;
        }
    
        public void setType(String type) {
            this.type = type;
        }
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
    }
    

    Please let me know if you are facing any issue.

提交回复
热议问题