Skip to content

docs(py2go): fix JSON struct tag examples in module 4 - #51

Open
tech-fever wants to merge 1 commit into
erweixin:mainfrom
tech-fever:fix/json-struct-tags
Open

docs(py2go): fix JSON struct tag examples in module 4#51
tech-fever wants to merge 1 commit into
erweixin:mainfrom
tech-fever:fix/json-struct-tags

Conversation

@tech-fever

@tech-fever tech-fever commented Aug 23, 2026

Copy link
Copy Markdown

Fix invalid json:"internal,internal" option, document the four encoding/json tag options (omitempty, string, omitzero, -), and fix the duplicate JSON key collision between Name and DBName across en/zh-cn/zh-tw.

概述

修复 py2go 第 4 模块(Structs and Interfaces)结构体标签示例中的两处问题。

改动

  1. 移除无效的 json:"internal,internal" 选项
    encoding/json 并不支持 internal 这个选项,未知选项会被静默忽略。
    已改为合法的 json:"internal,omitempty"。并且示例中 Internal 留空来示范 omitempty 的作用。

  2. 补充 encoding/json 支持的四个选项说明
    omitemptystringomitzero(Go 1.24+)、-,帮助读者理解正确的标签写法。

  3. 修复 NameDBName 的 JSON 键冲突
    DBName 原使用 json:"name",会与 Name 字段产生重复键,序列化输出会有歧义,已改为 json:"db_name"

范围

同步更新了英文、简体中文、繁体中文三个版本。

- Remove invalid `json:"internal,internal"` option (internal is not
  supported; unknown options are silently ignored)
- Document the four encoding/json tag options: omitempty, string,
  omitzero, "-"
- Fix duplicate JSON key collision between Name and DBName fields
  (DBName json tag changed to "db_name")
- Apply consistently across en, zh-cn, zh-tw
@tech-fever

tech-fever commented Aug 23, 2026

Copy link
Copy Markdown
Author

原来的代码可以跑,是因为错误被静默忽略,但写法是有问题的:
image

name 重复所以 json 结果中并没有:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant