Jsonpath如何select this json with inner json node

Jsonpath how to select this json with inner json node

Jsonpath 对我来说是新的,我正在学习它。我只能select 将name as $.name。我不知道如何从这个jsonselectemployeenametype?谁能告诉我怎么做?

{

"name": "{\r\n  \"employeename\": \"Test  name\"\r\n}\r\n",

" availability": {

    "available": true,

    "type": "private"

},

"is_available": true
}

此代码为:

@Test
void SO_69565621() throws JsonProcessingException {
    String text = "{\n" +
            "  \"name\": \"{\r\n  \\"employeename\\": \\"Test  name\\"\r\n}\r\n\",\n" +
            "  \" availability\": {\n" +
            "    \"available\": true,\n" +
            "    \"type\": \"private\"\n" +
            "  },\n" +
            "  \"is_available\": true\n" +
            "}";
    String name = JsonPath.read(text, "$.name");
    JsonNode jsonNode = new ObjectMapper().readTree(name);
    MatcherAssert.assertThat(jsonNode.get("employeename").asText(), Matchers.is("Test  name"));
}

我正在使用 Jackson 将 String 转换为 JsonNode,然后获取此 JsonNode 的值。

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.12.4</version>
</dependency>