我正在开发使用配置文件的软件。我不知道很多配置文件的语法或格式。下面是我所知道的两个:
(常用于.conf文件)
[section]
key=value
#comment或(在.ini中常见)
key value
; comment我的兴趣是多才多艺,几乎是一门语言。比方说
[Default]
Start = 0
End = 10
Speed = 1
[Section 3-6]
Speed = 2这将作为覆盖。然而,据我所知,这不是任何约定。有没有一种通用的语法可以做到这一点?
发布于 2011-09-08 22:56:01
这个曾经有效的答案将在2020年被否决,所以我对它进行了编辑。
在2011年,我建议您使用xml格式。这是当时事实上的标准。
配置文档可能如下所示:
<?xml version="1.0" encoding="utf-8">
<configuraton>
<default>
<start>0</start>
<end>10</end>
<speed>1</speed>
</default>
<section from="3" to="6">
<speed>2</speed>
</section>
</configuration>有很多库可以解析这样的文件。
发布于 2015-05-28 23:28:08
从2015年开始,xml不再是事实上的标准。这里有一些选项。
# This is a TOML document.
title = "TOML Example"
[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00-08:00
[servers]
# tabs / spaces ok but not required
[servers.alpha]
ip = "10.0.0.1"
dc = "eqdc10"%YAML 1.2
---
YAML: YAML Ain't Markup Language
Projects:
C/C++ Libraries:
- libyaml # "C" Fast YAML 1.1
- Syck # (dated) "C" YAML 1.0
- yaml-cpp # C++ YAML 1.2 implementation# Comments!!!
greatDocumentaries: [
'earthlings.com'
'forksoverknives.com'
]
importantFacts:
# Multi-Line Strings! Without Quote Escaping!
emissions: '''
Livestock and their byproducts account for at least 32,000 million tons of carbon dioxide (CO2) per year, or 51% of all worldwide greenhouse gas emissions.
'''JSON5和Human JSON -灵活的json超集
Properties File -由java程序使用
https://stackoverflow.com/questions/7349907
复制相似问题