【发布时间】:2017-05-25 13:41:09
【问题描述】:
{
"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"
}
]
}
}
}
}
我需要解析上面的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);
为了解析它们,我制作了 One Pojo 类。 但问题是“Datewise”jsons 数组的键是动态的,在我当前的 pojo 类中,我采用了预定义的键,因此无法解析它们。
{
"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"
}
有没有办法动态解析“Datewise”json 数组的值?
【问题讨论】:
-
如果有帮助请查看此链接stackoverflow.com/a/43347314/1252158