三种配置格式
| 格式 | 典型用途 | 特点 |
|---|---|---|
| TOML | Rust(Cargo)、Go、Python(pyproject) | 语义明确,支持嵌套表 |
| INI | Windows配置、Python(old) | 简单的[section]键值对 |
| Properties | Java/Spring | key=value格式,支持注释 |
互转示例
以TOML为例:
[server]
host = "localhost"
port = 8080
转为JSON:
{"server": {"host": "localhost", "port": 8080}}
转为INI:
[server]
host = localhost
port = 8080
注意:Properties的中文键值需要确保文件编码为UTF-8,否则可能出现乱码。