Use TOML arrays 和数组的 tables
TOML supports arrays 的 primitives 和 arrays 的 tables. Learn syntax 为 inline arrays, multi-行 arrays, 和 [[表]] arrays 为 structured 数据.
- 1
TOML arrays: inline ([1, 2, 3]) 或 multi-行 (one 元素 per 行具有 trailing comma). 数组的 tables 我们 [[表]] — 每个 occurrence appends 新元素到 数组. 此是 useful 为 lists 的 structured objects (e.g., [[servers]] 具有 name, 主机, 端口).
- 2 TOML 转换器 →
解析 the TOML file and convert to JSON to verify array structures. Inline arrays become JSON arrays; [[table]] becomes an array of objects. The conversion makes the structure explicit and easy to inspect.
- 3 JSON 格式化器 →
格式化 the converted JSON to see the array structure clearly. Arrays of tables become arrays of objects — verify the nesting and element count. This is useful for debugging TOML parsing issues.
- 4
- 5
TOML 数组 syntax: inline = [1, 2, 3], multi-行 = [ 1, 2, 3 ], 数组的 tables = [[product]] name = "" [[product]] name = "B". Mixed-类型 arrays 是允许在 TOML 1.0 但 discouraged. Use arrays 的 tables 为 lists 的配置 objects (servers, endpoints, features).
常见问题
- 能够 TOML arrays 包含 mixed types?
- TOML 1.0 allows mixed-类型 arrays: [1, "two", 真]. However, 此是 discouraged — 它 makes parsing 和 validation harder. Use homogeneous arrays (所有 strings, 所有 integers, 所有 tables) 为 clarity 和类型安全性.
- 如何数组的 tables 不同从 inline arrays 的 tables?
- [[表]] creates 数组的 tables 通过 appending 每个 occurrence. 你能够 also 写入 inline: products = [{name = "", price = 1}, {name = "B", price = 2}]. [[表]] form 是 preferred 为 readability 具有许多 fields; inline 是 fine 为短 entries.