我想使用杰克逊对象映射器获取多个 Json 对象数组的大小.如何在不使用杰克逊树的情况下获得它


<b>Here is Json:</b>
[{"index":"incident","type":"SmbIncident"},
{"index":"incident","type":"SmbIncident"}
]

IndexPortion is class how can i get both Json object size.

IndexPortion= new ObjectMapper((.readValue(new File(path(, 索引部分.class(;

首先,您应该为 json 对象创建一个实体:

public class MyEntity implements Serializable{
    private String index;
    private String type;
    // getter and setter
}

然后,您可以从这篇文章中将json数组转换为与JsonUtil一起列出:

List<MyEntity> entities= JsonUtil.toObject(jsonString,
                            new TypeReference<List<MyEntity>>() {});
int size = entities.size();

相关内容

最新更新