此代码将是:
@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>