# com.fasterxml.jackson.core.JsonParseException: 意外字符 ('<' (代码 60)): 期望一个有效值（JSON 字符串、数字、数组、对象或标记 'null'、'true' 或 'false'）

- **ID:** `java/jackson-jsonparseexception-unexpected-char`
- **领域:** java
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

Jackson 尝试解析包含非 JSON 内容的响应或输入，通常是一个 HTML 页面（以 '<' 开头）而不是有效的 JSON，通常是由于错误的 URL、服务器错误响应或缺少 API 端点。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Jackson 2.13 | active | — | — |
| Jackson 2.14 | active | — | — |
| Jackson 2.15 | active | — | — |
| Jackson 2.16 | active | — | — |

## 解决方案

1. ```
   Check the actual response from the server by logging the raw response string before parsing. For example: System.out.println("Response: " + responseBody); and verify the URL or API endpoint.
   ```
2. ```
   Use a debug proxy like Fiddler or Charles Proxy to capture the HTTP response and confirm it's HTML instead of JSON. Then fix the request URL or handle HTTP error codes (e.g., 404, 500) gracefully.
   ```
3. ```
   Add a response content-type check before parsing: if (response.getHeader("Content-Type").contains("application/json")) { parse; } else { handle error; }
   ```

## 无效尝试

- **Add @JsonIgnoreProperties(ignoreUnknown = true) to the POJO class** — This annotation ignores unknown JSON properties but does not help when the input is not JSON at all (e.g., HTML). (95% 失败率)
- **Increase the Jackson parsing leniency with ObjectMapper.enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES)** — These features relax JSON syntax rules but still require valid JSON structure; they cannot parse HTML. (90% 失败率)
- **Wrap the parsing in a try-catch and return an empty object** — This hides the error but does not address the root cause (the server returning HTML). The application may behave incorrectly. (80% 失败率)
