import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; public class DraftUrlTest { private static final ObjectMapper objectMapper = new ObjectMapper(); public static String extractDraftUrl(String jsonString) { if (jsonString == null || jsonString.isEmpty()) { return null; } try { JsonNode rootNode = objectMapper.readTree(jsonString); JsonNode outputNode = rootNode.get("Output"); if (outputNode == null || !outputNode.isObject()) { return null; } JsonNode draftUrlNode = outputNode.get("output"); if (draftUrlNode == null || !draftUrlNode.isTextual()) { return null; } String draftUrl = draftUrlNode.asText(); draftUrl = draftUrl.replaceAll("\\\"", ""); return draftUrl; } catch (IOException e) { return null; } } public static void main(String[] args) { String testJson = "{\"node_status\":\"0\",\"Output\":{\"output\":\"https://www.1818ai.com/api/v1/drafts/download_draft?draft_id=040ac6aa-a786-4fa5-8dee-506ba1d6c35d\"}}"; String draftUrl = extractDraftUrl(testJson); System.out.println("提取的draft_url: " + draftUrl); System.out.println("测试结果: " + (draftUrl != null ? "成功" : "失败")); } }