# 我们的根对象 (它们在整个文件里延续) 将会是一个映射, # 它等价于在别的语言里的一个字典,哈希表或对象。 key:value another_key:Anothervaluegoeshere. a_number_value:100 # 数字 1 会被解释为数值,而不是一个布尔值。 # 如果你想要的是一个布尔值,使用 true。 scientific_notation:1e+12 boolean:true null_value:null keywithspaces:value # 注意,字符串不必被括在引号中,但也可以被括起来。 however:'A string, enclosed in quotes.' 'Keys can be quoted too.':"Useful if you want to put a':'in your key." singlequotes:'have''one''escape pattern' doublequotes:"have many: \", \0, \t, \u263A, \x0d\x0a == \r\n, and more." # UTF-8/16/32 字符需要被转义 (encoded) Superscripttwo:\u00B2
# 多行字符串既可以写成像一个'文字块'(使用 |), # 或像一个'折叠块'(使用'>')。 literal_block:| This entire block of text will be the value of the'literal_block'key, with line breaks being preserved. The literal continues until de-dented, and the leading indentation is stripped. Any lines that are'more-indented'keep the rest of their indentation - these lines will be indented by 4 spaces. folded_style:> This entire block of text will be the value of'folded_style', but this time, all newlines will be replaced with a single space. Blank lines, like above, are converted to a newline character. 'More-indented'lines keep their newlines, too - this text will appear over two lines. #################### # 集合类型 # #################### # 嵌套是通过缩进完成的。推荐使用 2 个空格的缩进(但非必须) a_nested_map: key:value another_key:AnotherValue another_nested_map: hello:hello
# 映射的键不必是字符串。 0.25:afloatkey
# 键也可以是复合型的,比如多行对象 # 我们用 ? 后跟一个空格来表示一个复合键的开始。 ?| This is a key that has multiple lines : and this is its value # YAML 也允许使用复杂键语法表示序列间的映射关系。 # 但有些语言的解析器可能会不支持。 # 一个例子: ? - Manchester United - Real Madrid : [ 2001-01-01, 2002-02-02 ] # 序列 (等价于列表或数组) 看起来像这样: # 注意'-'算作缩进 a_sequence: -Item1 -Item2 -0.5# 序列可以包含不同类型。 -Item4 - key:value another_key:another_value - -Thisisasequence -insideanothersequence ---Nestedsequenceindicators -canbecollapsed