Article Directory
1. Introduction
- YAML is a recursive acronym for "YAML Ain't a Markup Language" (YAML is not a markup language). When developing this language, YAML actually meant: "Yet Another Markup Language" (still a markup language).
- It is very suitable for data-centric configuration files.
2. Basic grammatical structure
- key: value; key: there is a space between value
- Case Sensitive
- Use indentation to indicate hierarchical relationships
- Tabs are not allowed for indentation, only spaces are allowed (but you can rest assured to use tabs for indentation in idea, there is no problem at present)
- The number of indented spaces is not important, as long as the elements of the same level are aligned to the left
- '#' means comment
- String is not to be quoted, if you want to add,
""
and''
a string representing the content will not be escaped or escaped.- The
''
content of the single quote string will not be escaped, for example, it' \n '
will output the string \n - Double quotes
""
string contents are escaped, for example"\n "
will \ n escape the line feed output transducer
- The
1. When the data type is literal
- Literal: A single, indivisible value. date, boolean, string, number, null
:( syntax k:
and v
you must be a space between.)
#`k:`与`v`之间必须加空格
k: v
2. When the data type is a collection of objects and key-value pairs
- Collection of objects and key-value pairs: map, hash, set, object
The grammar is: ( no space can be added between k:
and when writing in a line, and a v
space must be added between k:
and when writing in general v
)
#行内写法:(行内写法时`k:`与`v`之间可以不加空格)
k: {
k1:v1,k2:v2,k3:v3}
#或一般写法:(一般写法时`k:`与`v`之间必须加空格)
k:
k1: v1
k2: v2
k3: v3
3. When the data type is an array, a set of values in order
- Array, a set of values in order: array, list, queue
The syntax is :( k:
and v
between, -
and v
all must be a space between)
#`k:`与`v`之间,`-`与`v`之间都必须加空格
行内写法: k: [v1,v2,v3]
#或者
k:
- v1
- v2
- v3
Practical example:
Output result: