使用Jackson反序列化嵌套的值数组 [英] deserializing nested array of values using Jackson

查看:160
本文介绍了使用Jackson反序列化嵌套的值数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含嵌套数组值的json文件:

I have a json file that contains a nested array of values:

[
    {"target": "dsdsa", 
     "datapoints": 
        [
            [94.283, 1435080720], 
            [94.233, 1435080780], 
            ....
        ]
     }
]

我在解析内部嵌套数组时遇到问题。我正在使用Spring和Jackson。我首先使用以下方法解析外部数组:

I'm having problem parsing inner nested arrays. I'm using Spring and Jackson. I first parse the outer array using:

Output[] allJson = restTemplate.getForObject("json/url",Output[].class);

其中Output是POJO:

where Output is a POJO:

public class Output
{
    public String target;
    //public Datapoint[] datapoints;
}   

public class Datapoint 
{
    private double[] points;
}

使用这个我可以从json访问target。但如果我取消注释,Jackson无法将数组数组映射到Datapoints。

Using this I can access the "target" from the json. But if I uncomment it, Jackson is not able to map the array of array of values to the Datapoints.

我还需要另一个包装类吗?
我找不到任何例子,除了json对象和杰克逊解析它之外还有什么东西。

Do I need another wrapper class? I couldn't find any example where inside the array there is anything except json objects and Jackson parses it.

推荐答案

[94.283,1435080720] 数据点内部不是json对象,但它是一个json列表。您将不得不使用二维数组或列表中的列表来获取数据点。使用

[94.283, 1435080720] inside datapoints is not a json object but it's a json list. You will have to use two dimentional array or a list within a list for datapoints. Use

public double [] [] datapoints; List< List< Double> > datapoints

这篇关于使用Jackson反序列化嵌套的值数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆