拓展閱讀
toml-01-toml 配置文件介紹
YAML-01-yml 配置文件介紹
YAML-02-yml 配置文件 java 整合使用 yamlbeans + snakeyaml + jackson-dataformat-yaml
YAML
YAML 是一種面向所有編程語(yǔ)言的人類友好的數(shù)據(jù)序列化標(biāo)準(zhǔn)。
zh_cn
特性
-
大小寫敏感
-
使用縮進(jìn)表示層級(jí)關(guān)系
-
縮進(jìn)時(shí)不允許使用Tab鍵,只允許使用空格。
-
縮進(jìn)的空格數(shù)目不重要,只要相同層級(jí)的元素左側(cè)對(duì)齊即可
-
#
表示注釋,從這個(gè)字符一直到行尾,都會(huì)被解析器忽略
Test
對(duì)象
- 使用
:
分隔,右側(cè)必須有空格。
name: ryo
在 JavaScript 中:
{ name: 'ryo' }
- 或者像這樣
person: {name: ryo, age: 21}
在 JavaScript 中:
{ person: { name: 'ryo', age: 21 } }
數(shù)組
以 -
開始,例如:
- apple
- box
- cat
- dog
在 JavaScript 中:
[ 'apple', 'box', 'cat', 'dog' ]
- 數(shù)組的子元素可以這樣表示
-
- apple
- box
- cat
在 JavaScript 中:
[ [ 'apple', 'box', 'cat' ] ]
- 內(nèi)聯(lián)數(shù)組
array: [apple, box]
在 JavaScript 中:
{ array: [ 'apple', 'box' ] }
多種類型的數(shù)組和對(duì)象:
names:
- Ryo
- Kyo
- May
animations:
- Key: Kanon
- Key: ReWrite
- Key: CLANNAD
在 JavaScript 中:
{ names: [ 'Ryo', 'Kyo', 'May' ],
animations: [ { Key: 'Kanon' }, { Key: 'ReWrite' }, { Key: 'CLANNAD' } ] }
基本類型
- 數(shù)字
age: 12
在 JavaScript 中:
{ age: 12 }
- 布爾值
使用 true
或 false
isTrue: false
在 JavaScript 中:
{ isTrue: false }
- 空值
使用 ~
表示 null
memory: ~
在 JavaScript 中:
{ memory: null }
- 時(shí)間
時(shí)間使用 ISO8601 類型:
time: 2016-10-26t21:59:43.10-05:00
在 JavaScript 中:
{ time: Thu Oct 27 2016 10:59:43 GMT+0800 (CST) }
- 日期
日期使用多種 ISO8601 年、月、日表示
date: 1970-01-01
在 JavaScript 中:
{ date: Thu Jan 01 1970 08:00:00 GMT+0800 (CST) }
- YAML 可以使用
!!
強(qiáng)制類型
name: !!str ryo
age: !!int '56'
在 JavaScript 中:
{ name: 'ryo', age: 56 }
字符串
字符串默認(rèn)不需要使用 ``
str: this is a string demo
在 JavaScript 中:
{ str: 'this is a string demo' }
如果字符串中有空格或特殊字符,使用 '' 或 ""
name: "hou: ryo"
在 JavaScript 中:
{ name: 'hou: ryo' }
'' 和 "" 的區(qū)別是:
- '' 中的特殊字符會(huì)被轉(zhuǎn)義,而 "" 中不會(huì)
double quote: "long \n long story"
single quote: 'long \n long story'
在 JavaScript 中:
{ 'double quote': 'long \n long story',
'single quote': 'long \\n long story' }
單引號(hào)中如果還有單引號(hào),必須連續(xù)使用兩個(gè)單引號(hào)轉(zhuǎn)義。
name: 'mary''s song'
在 JavaScript 中:
{ name: 'mary\'s song' }
字符串可以寫成多行,從第二行開始,必須有一個(gè)空格縮進(jìn)。換行符會(huì)被轉(zhuǎn)為空格。
long string
a
ha
ha
在 JavaScript 中:
'long string a ha ha'
多行字符串可以使用 |
保留換行符,也可以使用 >
折疊換行。
this: |
angle
beats
that: >
little
busters
在 JavaScript 中:
{ this: 'angle\nbeats\n', that: 'little busters\n' }
-
+
表示保留文字塊末尾的換行,-
表示刪除字符串末尾的換行。
one: |
Spring
two: |+
Summer
three: |-
Autumn
在 JavaScript 中:
{ one: 'Spring\n', two: 'Summer\n\n\n', three: 'Autumn' }
字符串可以插入 HTML。
string with html: |
<p class="red">
red
</p>
在 JavaScript 中:
{ 'string with html': '\n<p class="red">\n red\n</p>\n' }
引用
你可以像這樣使用:文章來源:http://www.zghlxwxcb.cn/news/detail-842907.html
Author: &author
name: ryo
age: 11
Blog:
info: learn note
<<: *author
Artile:
info: sth just like
<<: *author
在 JavaScript 中:文章來源地址http://www.zghlxwxcb.cn/news/detail-842907.html
{ Author: { name: 'ryo', age: 11 },
Blog: { info: 'learn note', name: 'ryo', age: 11 },
Artile: { info: 'sth just like', name: 'ryo', age: 11 } }
到了這里,關(guān)于YAM yml 配置文件介紹的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!