首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何利用重载的pojo构造器进行改造?

如何利用重载的pojo构造器进行改造?
EN

Stack Overflow用户
提问于 2015-04-23 19:17:22
回答 1查看 227关注 0票数 0

我想创建一个pojo,可以容纳系列一,当需要的时候,系列二。数据因年而异;1975年有雨数据,但1976年有雨和雪数据。换句话说,我希望我的pojo能够保存只有雨数据的年份的降雨数据,以及有雨/雪数据的年份的雨/雪数据。

代码语言:javascript
复制
{
    "status": "REQUEST_SUCCEEDED",
    "responseTime": 313,
    "message": [
        "No Data Available for Series 2 Year: 1975"
    ],
    "Results": {
        "series": [
            {
                "seriesID": "1",
                "data": [
                    {
                        "year": "1976",
                        "period": "M12",
                        "periodName": "December",
                        "value": "171.8",
                        "footnotes": [
                            {}
                        ]
                    },
                    {
                        "year": "1976",
                        "period": "M11",
                        "periodName": "November",
                        "value": "172.1",
                        "footnotes": [
                            {}
                        ]
                    },
                    {
                        "year": "1976",
                        "period": "M10",
                        "periodName": "October",
                        "value": "172.7",
                        "footnotes": [
                            {}
                        ]
                    },
                    {
                        "year": "1976",
                        "period": "M09",
                        "periodName": "September",
                        "value": "173.3",
                        "footnotes": [
                            {}
                        ]
                    },
                    {
                        "year": "1976",
                        "period": "M08",
                        "periodName": "August",
                        "value": "174.2",
                        "footnotes": [
                            {}
                        ]
                    },
                    {
                        "year": "1976",
                        "period": "M07",
                        "periodName": "July",
                        "value": "174.8",
                        "footnotes": [
                            {}
                        ]
                    },
                    {
                        "year": "1976",
                        "period": "M06",
                        "periodName": "June",
                        "value": "176.0",
                        "footnotes": [
                            {}
                        ]
                    },
                    {
                        "year": "1976",
                        "period": "M05",
                        "periodName": "May",
                        "value": "176.9",
                        "footnotes": [
                            {}
                        ]
                    },
                    {
                        "year": "1976",
                        "period": "M04",
                        "periodName": "April",
                        "value": "178.1",
                        "footnotes": [
                            {}
                        ]
                    },
                    {
                        "year": "1976",
                        "period": "M03",
                        "periodName": "March",
                        "value": "178.7",
                        "footnotes": [
                            {}
                        ]
                    },
                    {
                        "year": "1976",
                        "period": "M02",
                        "periodName": "February",
                        "value": "179.0",
                        "footnotes": [
                            {}
                        ]
                    },
                    {
                        "year": "1976",
                        "period": "M01",
                        "periodName": "January",
                        "value": "179.6",
                        "footnotes": [
                            {}
                        ]
                    },
                    {
                        "year": "1975",
                        "period": "M12",
                        "periodName": "December",
                        "value": "179.9",
                        "footnotes": [
                            {}
                        ]
                    },
                    {
                        "year": "1975",
                        "period": "M11",
                        "periodName": "November",
                        "value": "180.8",
                        "footnotes": [
                            {}
                        ]
                    },
                    {
                        "year": "1975",
                        "period": "M10",
                        "periodName": "October",
                        "value": "182.0",
                        "footnotes": [
                            {}
                        ]
                    },
                    {
                        "year": "1975",
                        "period": "M09",
                        "periodName": "September",
                        "value": "182.9",
                        "footnotes": [
                            {}
                        ]
                    },
                    {
                        "year": "1975",
                        "period": "M08",
                        "periodName": "August",
                        "value": "183.8",
                        "footnotes": [
                            {}
                        ]
                    },
                    {
                        "year": "1975",
                        "period": "M07",
                        "periodName": "July",
                        "value": "184.4",
                        "footnotes": [
                            {}
                        ]
                    },
                    {
                        "year": "1975",
                        "period": "M06",
                        "periodName": "June",
                        "value": "186.4",
                        "footnotes": [
                            {}
                        ]
                    },
                    {
                        "year": "1975",
                        "period": "M05",
                        "periodName": "May",
                        "value": "187.9",
                        "footnotes": [
                            {}
                        ]
                    },
                    {
                        "year": "1975",
                        "period": "M04",
                        "periodName": "April",
                        "value": "188.8",
                        "footnotes": [
                            {}
                        ]
                    },
                    {
                        "year": "1975",
                        "period": "M03",
                        "periodName": "March",
                        "value": "189.7",
                        "footnotes": [
                            {}
                        ]
                    },
                    {
                        "year": "1975",
                        "period": "M02",
                        "periodName": "February",
                        "value": "190.3",
                        "footnotes": [
                            {}
                        ]
                    },
                    {
                        "year": "1975",
                        "period": "M01",
                        "periodName": "January",
                        "value": "191.8",
                        "footnotes": [
                            {}
                        ]
                    }
                ]
            },
            {
                "seriesID": "2",
                "data": [
                    {
                        "year": "1976",
                        "period": "M12",
                        "periodName": "December",
                        "value": "47.5",
                        "footnotes": [
                            {}
                        ]
                    },
                    {
                        "year": "1976",
                        "period": "M11",
                        "periodName": "November",
                        "value": "47.7",
                        "footnotes": [
                            {}
                        ]
                    },
                    {
                        "year": "1976",
                        "period": "M10",
                        "periodName": "October",
                        "value": "47.8",
                        "footnotes": [
                            {}
                        ]
                    },
                    {
                        "year": "1976",
                        "period": "M09",
                        "periodName": "September",
                        "value": "47.8",
                        "footnotes": [
                            {}
                        ]
                    },
                    {
                        "year": "1976",
                        "period": "M08",
                        "periodName": "August",
                        "value": "47.7",
                        "footnotes": [
                            {}
                        ]
                    },
                    {
                        "year": "1976",
                        "period": "M07",
                        "periodName": "July",
                        "value": "47.3",
                        "footnotes": [
                            {}
                        ]
                    },
                    {
                        "year": "1976",
                        "period": "M06",
                        "periodName": "June",
                        "value": "46.8",
                        "footnotes": [
                            {}
                        ]
                    },
                    {
                        "year": "1976",
                        "period": "M05",
                        "periodName": "May",
                        "value": "45.5",
                        "footnotes": [
                            {}
                        ]
                    },
                    {
                        "year": "1976",
                        "period": "M04",
                        "periodName": "April",
                        "value": "44.9",
                        "footnotes": [
                            {}
                        ]
                    },
                    {
                        "year": "1976",
                        "period": "M03",
                        "periodName": "March",
                        "value": "45.1",
                        "footnotes": [
                            {}
                        ]
                    },
                    {
                        "year": "1976",
                        "period": "M02",
                        "periodName": "February",
                        "value": "45.5",
                        "footnotes": [
                            {}
                        ]
                    },
                    {
                        "year": "1976",
                        "period": "M01",
                        "periodName": "January",
                        "value": "45.9",
                        "footnotes": [
                            {}
                        ]
                    }
                ]
            }
        ]
    }
}
EN

回答 1

Stack Overflow用户

发布于 2015-04-23 19:46:06

我正在为数据数组中的对象创建POJO

代码语言:javascript
复制
public class WeatherData
{
public String year;
public String period;
public String periodName;
public String Value;
List<Footnotes> footnotes;
}

你可以自己创建getter和setter我不知道脚注,因为它总是空的,所以你可以根据你的意愿进行更改,你可以通过检查会话seriesID来检查它是雨数据还是雪数据,因为通过看到你的JSON,我认为seriesID 1包含雨数据,seriesID 2包含雪数据,但我建议@frek13也提到,如果你可以有两个变量,一个用于雨数据,一个用于雪数据,那会更好

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29821830

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档