xpzouying/xiaohongshu-mcp · error

解析未读数失败: %w

Error message

解析未读数失败: %w

What it means

UnreadCount 拿到未读数 JSON 后 json.Unmarshal 到 rawCount 失败:notificationCount 字段结构与 rawCount 定义不符(前端改版),数据本身非合法对象。

Source

Thrown at xiaohongshu/notification.go:125

	}

	res, err := page.Eval(`() => {
		const s = window.__INITIAL_STATE__;
		const c = s && s.notification && s.notification.notificationCount;
		return c ? JSON.stringify(c) : "";
	}`)
	if err != nil {
		return nil, fmt.Errorf("读取未读数失败: %w", err)
	}

	raw := res.Value.String()
	if raw == "" {
		return nil, fmt.Errorf("页面状态里没有未读数,可能未登录或页面结构已变化")
	}

	var count rawCount
	if err := json.Unmarshal([]byte(raw), &count); err != nil {
		return nil, fmt.Errorf("解析未读数失败: %w", err)
	}
	return &NotificationCount{
		Mentions:    count.Mentions,
		Likes:       count.Likes,
		Connections: count.Connections,
		Unread:      count.Unread,
	}, nil
}

// rawCount 是未读数在页面状态里的原始结构。
type rawCount struct {
	Mentions    int `json:"mentions"`
	Likes       int `json:"likes"`
	Connections int `json:"connections"`
	Unread      int `json:"unreadCount"`
}

// List 读取指定分区的通知列表。

View on GitHub (pinned to 332d196854)

Solutions

  1. 打印原始 JSON 核对字段类型
  2. 按当前页面结构更新 rawCount 字段定义
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at xiaohongshu/notification.go:125 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05). Data as JSON: /api/errors/3830d38846dc7cd3. Report an issue: GitHub.