InputStream 类型的 readAllBytes() 方法未定义

The method readAllBytes() is undefined for the type InputStream

我无法摆脱 The method readAllBytes() is undefined for the type InputStream 错误。 我认为这是由于我使用的版本引起的? JDK 合规性 1.8 请指教谢谢

if (http.getResponseCode() == 200) {                    
            ObjectMapper mapper = new ObjectMapper();           
            try (InputStream inputStream = http.getInputStream()) {
                String jsonContent = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
                JsonNode node = mapper.readTree(jsonContent);
                String Stytch_user_id = node.get("user_id").textValue();
                Object[] objects = getUserLogin(Stytch_user_id, "P0002","123456789");
            }       
        } else { 
            System.out.println("failed");
        }

使用 readTree(Reader r) 重载方法让 Jackson 为您读取流:

JsonNode node;
try (Reader in = new InputStreamReader(http.getInputStream(), StandardCharsets.UTF_8)) {
    ObjectMapper mapper = new ObjectMapper();
    node = mapper.readTree(in);
}

String Stytch_user_id = node.get("user_id").textValue();
Object[] objects = getUserLogin(Stytch_user_id, "P0002","123456789");