十万个为什么 API 返回字段全解:ret_code / contentlist / content 一文读懂
十万个为什么 API返回字段ret_codecontentlist接口文档 # 十万个为什么 API 返回字段全解:ret_code / contentlist / content 一文读懂
> 接口:十万个为什么(apiCode=1706)· 接入点:列表(1706-1) + 详情(1706-2) · 免费 · 返回格式:JSON · 适用人群:已接入 / 排障开发者 · 阅读时间:约 7 分钟
## 核心要点
- 业务数据全部包裹在 `showapi_res_body` 内,系统级字段(`showapi_res_code` 等)在它外层。
- 列表返回 `contentlist`(**数组**,每项 `{id, title}`)+ 分页三件套;详情返回 `title` + `content`(**整段字符串**,非数组)。
- 状态判断只看 `ret_code`:`"0"` 成功,其他为失败,失败时看 `remark`。
## Why:为什么要先搞清字段
接入后最常见的报错不是网络问题,而是"拿到的字段结构跟自己想的不一样":比如以为 `content` 是数组,结果它是整段文本;以为列表直接返回内容,结果只返回 `id` 和 `title`。先读这篇,能少踩一半坑。
## What:接口速览
| 项 | 列表(1706-1) | 详情(1706-2) |
|----|------|------|
| 地址 | `https://route.showapi.com/1706-1` | `https://route.showapi.com/1706-2` |
| 必填入参 | `keyword` | `id` |
| 核心出参 | `contentlist`、`allPages`、`allNum`、`maxResult` | `title`、`content` |
| 公共字段 | `ret_code`、`remark` | `ret_code`、`remark` |
## How:字段逐项说明
**系统级外层(两个接入点都有)**
| 字段 | 类型 | 说明 |
|------|------|------|
| `showapi_res_code` | int | 系统级状态码,0 为成功 |
| `showapi_res_error` | string | 系统级错误信息,成功时为空 |
| `showapi_res_id` | string | 本次请求标识 |
| `showapi_res_body` | object | 业务数据封装,下面所有字段都在这里 |
**列表接入点 `showapi_res_body`**
| 字段 | 类型 | 说明 |
|------|------|------|
| `ret_code` | string | `"0"` 成功,其他失败 |
| `remark` | string | 提示信息,如"查询成功!" |
| `contentlist` | array | 问题列表,每项 `{id, title}` |
| `id` | string(数组内) | 问题 id,作为详情接入点入参 |
| `title` | string(数组内) | 问题标题 |
| `allPages` | string | 总页数 |
| `currentPage` | string | 当前页码 |
| `allNum` | string | 符合条件的总数 |
| `maxResult` | string | 每页最大条数(示例为 50) |
**详情接入点 `showapi_res_body`**
| 字段 | 类型 | 说明 |
|------|------|------|
| `ret_code` | string | `"0"` 成功,其他失败 |
| `remark` | string | 提示信息 |
| `title` | string | 该条问答的标题 |
| `content` | string | **整段科普正文文本**(非数组) |
## 返回示例与解析
列表:
```json
{
"showapi_res_code": 0,
"showapi_res_body": {
"remark": "查询成功!",
"allPages": 5,
"ret_code": 0,
"contentlist": [
{"id": "5ba48fdbc1b458bb0892f6ff", "title": "地球名片"}
],
"currentPage": 1,
"allNum": 210,
"maxResult": 50
}
}
```
详情:
```json
{
"showapi_res_code": 0,
"showapi_res_body": {
"ret_code": 0,
"remark": "查询成功!",
"title": "为什么无声手枪射击时没声音?",
"content": "在无声手枪的枪管上套有一个圆筒形的消音器……"
}
}
```
> 注意:`content` 是**一段字符串**,不是数组,渲染时直接整段展示或自行按标点分段,不要当列表遍历。
## 进阶 / 边界
- **错误码枚举**:文档仅定义 `ret_code` "0"=成功 / 其他=失败,**未给出具体非 0 枚举值**,排障统一看 `remark`,不要套用其他接口的错误码(如 -2/-3)。
- **分页三件套**:`allNum` 是总数、`allPages` 是总页数、`maxResult` 是每页上限,三者配合 `page` 做翻页(详见[《分页查询详解》](https://www.showapi.com/guides/why100k-pagination-1706))。
- **无扩展字段**:本接口没有坐标系、预测类等额外字段,纯文本问答。
## FAQ
**Q1:ret_code 不等于 0 时有哪些具体错误码?**
文档未提供非 0 的具体枚举,统一以 `remark` 文案为准(通常为参数缺失或鉴权问题)。
**Q2:contentlist 是数组还是对象?**
是数组,每项是一个 `{id, title}` 对象;`id` 用于后续调详情。
**Q3:content 能不能当数组遍历?**
不能。`content` 是整段字符串,需自行做文本排版。
**Q4:allNum 和 allPages 有什么区别?**
`allNum` 是命中结果总数,`allPages` 是分页后的总页数。
**Q5:系统字段 showapi_res_code 和 body 里的 ret_code 都要判断吗?**
两者都建议关注:`showapi_res_code` 是系统级,非 0 说明请求本身异常;`ret_code` 是业务级,0 成功。稳妥起见两个都判。
## 相关能力 / 下一步阅读
- [十万个为什么 API:分页查询:page / allPages / allNum / maxResult 详解](https://www.showapi.com/guides/why100k-pagination-1706)
- [十万个为什么 API:列表→详情两接入点串联的全链路设计](https://www.showapi.com/guides/why100k-list-detail-flow-1706)
- [十万个为什么 API:5 分钟接入,从第一条问答到完整详情](https://www.showapi.com/guides/why100k-quickstart-1706)
- **本系列共 11 篇**:查看[十万个为什么 API 指南总目录](https://www.showapi.com/guides/why100k-guides-1706)