1

这是我的球衣服务返回的课程:

@XmlRootElement(name="chart-data")
public class ChartDataDto {
private List<Series> series = new ArrayList<>();

    public ChartDataDto()
    {

    }

    public void putSeries(String name, Integer... series)
    {
        this.series.add(new Series(name, series));
    }

    @XmlElement(name="series")
    public List<Series> getSeries()
    {
        return this.series;
    }

    @XmlRootElement(name="series")
    static class Series
    {
        @XmlElement(name="name")
        public String name;
        @XmlElement(name="values")
        public List<Integer> series;

        public Series()
        {

        }

        public Series(String name, Integer... series)
        {
            this.name = name;

            this.series = Arrays.asList(series);
        }
    }
}

返回的 JSON 字符串例如:

{"series":[
    {
        "name":"Series 1",
        "values":["1","2","2","3","3","4","4","5","5","6","6","7","7"]
    },{
        "name":"Series 2",
        "values":["7","7","6","6","5","5","4","4","3","3","2","2","1"]
    }
]}

但我认为正确的 JSON 字符串应该是:

{"series":[
    {
        "name":"Series 1",
        "values":[1,2,2,3,3,4,4,5,5,6,6,7,7]
    },{
        "name":"Series 2",
        "values":[7,7,6,6,5,5,4,4,3,3,2,2,1]
    }
]}

那里有什么问题?整数列表的类型错误?错误的注释?

4

1 回答 1

0

使用Jackson并且Gson您的代码运行良好。

于 2012-09-19T10:30:24.043 回答