使用Jackson遍历Json

时间:2019-05-26 15:47:37

标签: java json jackson

我想遍历包含以下内容的JSON文件 MyPojo的有效数组。我该怎么办?

<h1>Just an h1 element</h1>
<h2 class="h1">h2 element with the class "h1"</h2>

<div class="title title_size_medium">
  <h1>An h1 element inside a div with the class "title" and "title_size_medium"</h1>
</div>

我收到此错误:

JsonParser jp = jsonFactory.createParser(is); Iterator<MyPojo> iterator = objectMapper.readerFor(MyPojo.class).readValues(jp); while (iterator.hasNext()) { MyPojo p = iterator.next(); }

如果有其他允许我在映射的POJO上进行迭代的库,将感到高兴。

JSON示例:

Cannot deserialize instance of MyPojo out of START_ARRAY token at

Stacktrace不包含任何其他相关的错误消息!

[
    {
        "name" : "Alice",
        "age" : "22",
    },
    {
        "name" : "Bob",
        "age" : "99",
    },
    ...(really large json)
]

public class MyPojo {
     public String name;
     public int age;
}

0 个答案:

没有答案