编写字符串
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#字符串
#单行
username: admin
username1: "周杰\n伦" #双引号不转义
username2: '周杰\n伦' ##单引号转义
#多行
william:



william2: |




william3: >



回显的结果是:

1
2
3
4
5
6
{ username: 'admin',
username1: '周杰\n伦',
username2: '周杰\\n伦',
william: '一 二 三',
william2: '一\n二\n三\n',
william3: '一 二 三\n' }
强制转换
1
2
3
forceStr: !!str 123
forceBoll: !!str true
forceInt: !!int "123"

回显的结果是:

1
2
3
forceStr: '123',
forceBoll: 'true',
forceInt: 123 }
编写数组
1
2
3
4
5
6
#数组
myFavourite:
- backaetball
- football

myFavourite2: ["bass","bahddd"]

回显的结果是:

1
2
myFavourite: [ 'backaetball', 'football' ],
myFavourite2: [ 'bass', 'bahddd' ],
编写对象
1
2
3
4
5
6
7
8
#对象
autotest:
username: root
password: root
age: 18
male: true

autotest2: [{username: admin, password: root, age: 22, male: false}]

回显的结果是:

1
2
autotest: { username: 'root', password: 'root', age: 18, male: true },
autotest2: [ { username: 'admin', password: 'root', age: 22, male: false } ],
编写复合结构的
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#复合结构
companies:
-
id: 1
name: zhangsan
value: 10e+11

-
id: 2
name: lisi
value: 10e+12


websites:
baidu: www.baidu.com
google: www.google.com

回显的结果是:

1
2
3
4
companies: 
[ { id: 1, name: 'zhangsan', value: 1000000000000 },
{ id: 2, name: 'lisi', value: 10000000000000 } ],
websites: { baidu: 'www.baidu.com', google: 'www.google.com' } }
引用
1
2
3
4
5
6
7
8
#引用
father: &father_lastName
lastName:

son:
<<: *father_lastName
firstName:
age: 18

回显的结果是:

1
2
father: { lastName: '周' },
son: { lastName: '周', firstName: '董', age: 18 } }