英文:
Jackson - parse nested array of arrays
问题
以下是您要翻译的内容:
这里有一个JSON字符串:
{
  "status": 200,
  "result": [
    [
      123,
      "FOO",
      "BAR",
      456
    ],
    [
      123,
      "FOO",
      "BAR",
      456
    ]
  ]
}
我需要解析这个对象并获取status字段以及result JSON属性中的所有数组(可能会有1个或多个这样的数组)。
我使用了这个DTO:
@JsonIgnoreProperties(ignoreUnknown = true)
public class TestDto {
    @JsonProperty("status")
    private Integer status;
    public Integer getStatus() {
        return status;
    }
    public void setStatus(Integer status) {
        this.status = status;
    }
}
来解析JSON,但我不知道如何解析result数组。
是否可能使用这样简单的DTO文件来完成,还是我需要创建自定义的com.fasterxml.jackson.databind.JsonDeserializer?
英文:
There is this JSON string:
{
  "status": 200,
  "result": [
    [
      123,
      "FOO",
      "BAR",
      456
    ],
    [
      123,
      "FOO",
      "BAR",
      456
    ],
  ]
}
and I need to parse this object and get status field and all arrays in result JSON property. (There could be 1...n of these arrays.)
I use this DTO:
@JsonIgnoreProperties(ignoreUnknown = true)
public class TestDto {
    @JsonProperty("status")
    private Integer status;
    public Integer getStatus() {
        return status;
    }
    public void setStatus(Integer status) {
        this.status = status;
    }
}
to parse JSON but I have no idea how to parse the result array.
Is it possible to accomplish it with such simple DTO file or do I need to create custom com.fasterxml.jackson.databind.JsonDeserializer?
答案1
得分: 2
你可以使用任何2维数组。
两者都可以完成任务:
private Object[][] result;
和
private List<List<Object>> result;
可以完成任务。
英文:
You can use anything 2-dimensional.
Both:
private Object[][] result;
and
private List<List<Object>> result;
can do the job.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论