更新时间:2023-11-26 14:31:34
ObjectMapper mapper = new ObjectMapper();
JsonNode json = mapper.readTree("... your JSON ...");
使用 JsonNode
对象,然后可以调用 get(my)。get(deep)。get(structure)
获取所需的节点。
Using the JsonNode
object you can then call get("my").get("deep").get("structure")
to get the node you want.
一旦你掌握了那个节点,只需简单调用 mapper.treeToValue(myDeepJsonNode,Telephone [] .class)
就可以得到你的数组电话
。您也可以使用 TypeReference
获取列表。
Once you got your hands on that node, a simple call to mapper.treeToValue(myDeepJsonNode, Telephone[].class)
will get you your array ofTelephone
. You can get a list using a TypeReference
as well.
要深入 JsonNode
你也可以使用 findValue
和 findPath
方法。
To get to your deep JsonNode
you can also use the findValue
and findPath
methods.