简体   繁体   English

Jackson:从 JSON 数组中获取没有 id 的单个值

[英]Jackson: Get single value without id from JSON array

I try to access a single value that doesn't have an id in a JsonNode with the help of Jackson.我尝试在 Jackson 的帮助下访问在 JsonNode 中没有 id 的单个值。 The JSON looks like this: JSON 如下所示:


[
    {
        "annotatedClass": {
            "semanticType": ["T033"],
            "prefLabel": "Oesophageal reflux",
            ...
        }
     }
]

I want to get the value of semanticType.我想获取semanticType 的值。 I tried it with String semanticType = currentNode.get("annotatedClass").get("semanticType).at("/").asText() but this gave me an empty string.我用String semanticType = currentNode.get("annotatedClass").get("semanticType).at("/").asText()尝试了它,但这给了我一个空字符串。

Does anyone have an idea on how to achieve this?有没有人知道如何实现这一目标?

I solved it with this:我用这个解决了它:

String semanticType = currentNode.get("annotatedClass").get("semanticType").get(0).asText();

The key to success was get(0) .成功的关键是get(0)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM