這是理解和編寫 YAML 格式配置文件的快速參考備忘單。
YAML 是一種數(shù)據(jù)序列化語(yǔ)言,旨在供人類直接讀寫
.yaml 或 .yml 擴(kuò)展名結(jié)束您的 YAML 文件n1: 1 # 整數(shù)
n2: 1.234 # 浮點(diǎn)
s1: 'abc' # 字符串
s2: "abc" # 字符串
s3: abc # 字符串
b: false # 布爾類型
d: 2015-04-05 # 日期類型
{
"n1": 1,
"n2": 1.234,
"s1": "abc",
"s2": "abc",
"s3": "abc",
"b": false,
"d": "2015-04-05"
}
使用空格縮進(jìn)。 元素部分之間必須有空間。
some_thing: &VAR_NAME foobar
other_thing: *VAR_NAME
{
"some_thing": "foobar",
"other_thing": "foobar"
}
# A single line comment example
# block level comment example
# comment line 1
# comment line 2
# comment line 3
description: |
hello
world
{"description": "hello\nworld\n"}
parent: &defaults
a: 2
b: 3
child:
<<: *defaults
b: 4
{
"parent": {
"a": 2,
"b": 3
},
"child": {
"a": 2,
"b": 4
}
}
values: &ref
- Will be
- reused below
other_values:
i_am_ref: *ref
{
"values": [
"Will be",
"reused below"
],
"other_values": {
"i_am_ref": [
"Will be",
"reused below"
]
}
}
description: >
hello
world
{"description": "hello world\n"}
---
document: this is doc 1
---
document: this is doc 2
YAML使用---將指令與文檔內(nèi)容分開。
- Mark McGwire
- Sammy Sosa
- Ken Griffey
[
"Mark McGwire",
"Sammy Sosa",
"Ken Griffey"
]
hr: 65 # Home runs
avg: 0.278 # Batting average
rbi: 147 # Runs Batted In
{
"hr": 65,
"avg": 0.278,
"rbi": 147
}
attributes:
- a1
- a2
methods: [getter, setter]
{
"attributes": ["a1", "a2"],
"methods": ["getter", "setter"]
}
children:
- name: Jimmy Smith
age: 15
- name: Jimmy Smith
age: 15
-
name: Sammy Sosa
age: 12
{
"children": [
{"name": "Jimmy Smith", "age": 15},
{"name": "Jimmy Smith", "age": 15},
{"name": "Sammy Sosa", "age": 12}
]
}
my_sequences:
- [1, 2, 3]
- [4, 5, 6]
-
- 7
- 8
- 9
- 0
{
"my_sequences": [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9, 0]
]
}
Mark McGwire: {hr: 65, avg: 0.278}
Sammy Sosa: {
hr: 63,
avg: 0.288
}
{
"Mark McGwire": {
"hr": 65,
"avg": 0.278
},
"Sammy Sosa": {
"hr": 63,
"avg": 0.288
}
}
Jack:
id: 1
name: Franc
salary: 25000
hobby:
- a
- b
location: {country: "A", city: "A-A"}
{
"Jack": {
"id": 1,
"name": "Franc",
"salary": 25000,
"hobby": ["a", "b"],
"location": {
"country": "A", "city": "A-A"
}
}
}
set1: !!set
? one
? two
set2: !!set {'one', "two"}
{
"set1": {"one": null, "two": null},
"set2": {"one": null, "two": null}
}
集合表示為一個(gè)映射,其中每個(gè)鍵都與一個(gè)空值相關(guān)聯(lián)
ordered: !!omap
- Mark McGwire: 65
- Sammy Sosa: 63
- Ken Griffy: 58
{
"ordered": [
{"Mark McGwire": 65},
{"Sammy Sosa": 63},
{"Ken Griffy": 58}
]
}
基于 YAML.org refcard。
| :- | :- |
|---|---|
% | 指令指標(biāo) |
--- | 文檔標(biāo)題 |
... | 文檔終結(jié)者 |
| :- | :- |
|---|---|
? | 關(guān)鍵指標(biāo) |
: | 價(jià)值指標(biāo) |
- | 嵌套系列條目指示器 |
, | 單獨(dú)的內(nèi)聯(lián)分支條目 |
[] | 環(huán)繞串聯(lián)系列分支 |
{} | 環(huán)繞在線鍵控分支 |
| :- | :- |
|---|---|
& | 錨屬性 |
* | 別名指示符 |
| :- | :- |
|---|---|
= | 默認(rèn)“值”映射鍵 |
<< | 合并來(lái)自另一個(gè)映射的鍵 |
| :- | :- |
|---|---|
'' | 環(huán)繞內(nèi)聯(lián)未轉(zhuǎn)義標(biāo)量 |
" | 環(huán)繞內(nèi)嵌轉(zhuǎn)義標(biāo)量 |
| ` | ` |
> | 折疊標(biāo)量指示器 |
- | 剝離 chomp 修飾符(|- 或 >-) |
+ | 保留 chomp 修飾符(|+ 或 >+) |
1-9 | 顯式縮進(jìn)修飾符(|1 或 >2)。 修飾符可以組合( |2-, >+1) |
| :- | :- |
|---|---|
none | 未指定的標(biāo)簽(由應(yīng)用程序自動(dòng)解析) |
! | 非特定標(biāo)簽(默認(rèn)情況下,!!map/!!seq/!!str) |
!foo | 主要(按照慣例,表示本地 !foo 標(biāo)記) |
!!foo | 次要的(按照慣例,表示 tag:yaml.org,2002:foo) |
!h!foo | 需要 %TAG !h! <prefix>(然后表示 <prefix>foo) |
!<foo> | 逐字標(biāo)記(始終表示“foo”) |
# | 一次性評(píng)論指示器 |
`@ | 兩者都保留供將來(lái)使用 |
!!map | {Hash table, dictionary, mapping} |
!!seq | {List, array, tuple, vector, sequence} |
!!str | Unicode 字符串 |
\x12 (8-bit)\u1234 (16-bit)\U00102030 (32-bit)\\ (\)\" (")\ ( )\<TAB> (TAB)\0 (NUL)\a (BEL)\b (BS)\f (FF)\n (LF)\r (CR)\t (TAB)\v (VTAB)\e (ESC)\_ (NBSP)\N (NEL)\L (LS)\P (PS)!!set | {cherries, plums, apples} |
!!omap | [one: 1, two: 2] |
{~, null} | 空(無(wú)值)。 |
[1234, 0x4D2, 02333] | [十進(jìn)制整數(shù)、十六進(jìn)制整數(shù)、八進(jìn)制整數(shù)] |
[1_230.15, 12.3015e+02] | [固定浮點(diǎn)數(shù),指數(shù)浮點(diǎn)數(shù)] |
[.inf, -.Inf, .NAN] | [無(wú)窮大(浮點(diǎn)數(shù)),負(fù)數(shù),不是數(shù)字] |
{Y, true, Yes, ON} | 布爾真 |
{n, FALSE, No, off} | 布爾假 |
感谢您访问我们的网站,您可能还对以下资源感兴趣:
国产成人精品999视频&日本一区二区亚洲人妻精品&久久久精品国产99久久精&99热这里只有成人精品国产&精品国产剧情av一区二区&成人亚洲精品久久久久app&国产精品美女高潮抽搐A片