0
{
    "Response": {
        "Header": {
            "StatusCode": 100,
            "Status": "Success",
            "Desc": "Success"
        },
        "Data": {
            "ComparisionsOfReportProducts": {
                "Datewise": [
                    {
                        "ReportDate": "04/11/2017",
                        "BT": "909",
                        "Ee": "1168",
                        "MG": "619",
                        "PY": "973",
                        "PF": "894",
                        "PA": "768",
                        "PX": "943"
                    },
                    {
                        "ReportDate": "04/14/2017",
                        "BT": "889",
                        "Ee": "1186",
                        "MG": "599",
                        "PY": "953",
                        "PF": "874",
                        "PA": "786",
                        "PX": "961"
                    },
                    {
                        "ReportDate": "04/16/2017",
                        "BT": "1162",
                        "Ee": "932",
                        "MG": "872",
                        "PY": "1226",
                        "PF": "1147",
                        "PA": "532",
                        "PX": "707"
                    },
                    {
                        "ReportDate": "04/18/2017",
                        "BT": "1020",
                        "Ee": "1055",
                        "MG": "730",
                        "PY": "1084",
                        "PF": "1005",
                        "PA": "655",
                        "PX": "830"
                    }
                ]
            }
        }
    }
}

I need to parse above Json.

 @FormUrlEncoded
    @POST("services/webservices/")
    Observable<ResComparision> getcomparisionDetail(@Field(value = "encAuthToken", encoded = true)String token,
                                                    @Field(value = "itemId", encoded = true) String productId,
                                                    @Field(value = "FromDate", encoded = true)String sdate,
                                                    @Field(value = "ToDate", encoded = true)String edate);

To Parse them i have made One Pojo class. But the Issue is Keys of "Datewise" jsons array's keys are coming dynamic and in my current pojo class i have taken predefined keys so it is unable to parse them.

  {
                                "ReportDate": "04/18/2017",
                                "BT": "1020",
                                "Ee": "1055",
                                "MG": "730",
                                "PY": "1084",
                                "PF": "1005",
                                "PA": "655",
                                "PQA": "655",
                                "PX": "830"
                            },
   {
                                "ReportDate": "04/18/2017",
                                "PP": "1020",
                                "QB": "1055",
                                "MG": "730",
                                "PY": "1084",
                                "PF": "1005",
                                "PA": "655",
                                "VA": "655",
                                "PX": "830"
                            }

Is there any way to get parse "Datewise" json array's value dynamically?

Raj
  • 844
  • 2
  • 11
  • 29

1 Answers1

-3

Use GSON to parse this.For pojo class use this site. http://www.jsonschema2pojo.org/

select below Source type: JSON, Annotation style: Gson

Click on Preview your pojo classes will be ready.

Abhishek Kumar
  • 1,255
  • 13
  • 21