当前位置:   article > 正文

YAM yml 配置文件介绍

YAM yml 配置文件介绍

拓展阅读

toml-01-toml 配置文件介绍

YAML-01-yml 配置文件介绍

YAML-02-yml 配置文件 java 整合使用 yamlbeans + snakeyaml + jackson-dataformat-yaml

YAML

YAML 是一种面向所有编程语言的人类友好的数据序列化标准。

zh_cn

特性

  • 大小写敏感

  • 使用缩进表示层级关系

  • 缩进时不允许使用Tab键,只允许使用空格。

  • 缩进的空格数目不重要,只要相同层级的元素左侧对齐即可

  • # 表示注释,从这个字符一直到行尾,都会被解析器忽略

Test

对象

  • 使用 : 分隔,右侧必须有空格。
name: ryo

    在 JavaScript 中:

    { name: 'ryo' }
      • 或者像这样
      person: {name: ryo, age: 21}

        在 JavaScript 中:

        { person: { name: 'ryo', age: 21 } }

          数组

          - 开始,例如:

          - apple
          - box
          - cat
          - dog
          • 1
          • 2
          • 3

          在 JavaScript 中:

          [ 'apple', 'box', 'cat', 'dog' ]
            • 数组的子元素可以这样表示
            -
              - apple
              - box
              - cat
            • 1
            • 2
            • 3

            在 JavaScript 中:

            [ [ 'apple', 'box', 'cat' ] ]
              • 内联数组
              array: [apple, box]

                在 JavaScript 中:

                { array: [ 'apple', 'box' ] }

                  多种类型的数组和对象:

                  names:
                   - Ryo
                   - Kyo
                   - May
                  animations:
                   - Key: Kanon
                   - Key: ReWrite
                   - Key: CLANNAD
                  • 1
                  • 2
                  • 3
                  • 4
                  • 5
                  • 6
                  • 7

                  在 JavaScript 中:

                  { names: [ 'Ryo', 'Kyo', 'May' ],
                    animations: [ { Key: 'Kanon' }, { Key: 'ReWrite' }, { Key: 'CLANNAD' } ] }
                  • 1

                  基本类型

                  • 数字
                  age: 12

                    在 JavaScript 中:

                    { age: 12 }
                      • 布尔值

                      使用 truefalse

                      isTrue: false

                        在 JavaScript 中:

                        { isTrue: false }
                          • 空值

                          使用 ~ 表示 null

                          memory: ~

                            在 JavaScript 中:

                            { memory: null }
                              • 时间

                              时间使用 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 可以使用 !! 强制类型
                                      name: !!str ryo
                                      age: !!int '56'
                                      • 1

                                      在 JavaScript 中:

                                      { name: 'ryo', age: 56 }

                                        字符串

                                        字符串默认不需要使用 ``

                                        str: this is a string demo

                                          在 JavaScript 中:

                                          { str: 'this is a string demo' }

                                            如果字符串中有空格或特殊字符,使用 ''""

                                            name: "hou: ryo"

                                              在 JavaScript 中:

                                              { name: 'hou: ryo' }

                                                ''"" 的区别是:

                                                • '' 中的特殊字符会被转义,而 "" 中不会
                                                double quote: "long \n long story"
                                                single quote: 'long \n long story'
                                                • 1

                                                在 JavaScript 中:

                                                { 'double quote': 'long \n long story',
                                                  'single quote': 'long \\n long story' }
                                                • 1

                                                单引号中如果还有单引号,必须连续使用两个单引号转义。

                                                name: 'mary''s song'

                                                  在 JavaScript 中:

                                                  { name: 'mary\'s song' }

                                                    字符串可以写成多行,从第二行开始,必须有一个空格缩进。换行符会被转为空格。

                                                    long string
                                                     a
                                                     ha
                                                     ha
                                                    • 1
                                                    • 2
                                                    • 3

                                                    在 JavaScript 中:

                                                    'long string a ha ha'

                                                      多行字符串可以使用 | 保留换行符,也可以使用 > 折叠换行。

                                                      this: |
                                                       angle
                                                       beats
                                                      that: >
                                                       little
                                                       busters
                                                      • 1
                                                      • 2
                                                      • 3
                                                      • 4
                                                      • 5

                                                      在 JavaScript 中:

                                                      { this: 'angle\nbeats\n', that: 'little busters\n' }
                                                        • + 表示保留文字块末尾的换行,- 表示删除字符串末尾的换行。
                                                        one: |
                                                         Spring
                                                        
                                                        two: |+
                                                         Summer
                                                        
                                                        
                                                        three: |-
                                                         Autumn
                                                        • 1
                                                        • 2
                                                        • 3
                                                        • 4
                                                        • 5
                                                        • 6
                                                        • 7
                                                        • 8

                                                        在 JavaScript 中:

                                                        { one: 'Spring\n', two: 'Summer\n\n\n', three: 'Autumn' }

                                                          字符串可以插入 HTML

                                                          string with html: |
                                                          
                                                           <p class="red">
                                                               red
                                                           </p>
                                                          • 1
                                                          • 2
                                                          • 3
                                                          • 4

                                                          在 JavaScript 中:

                                                          { 'string with html': '\n<p class="red">\n    red\n</p>\n' }

                                                            引用

                                                            你可以像这样使用:

                                                            Author: &author
                                                              name: ryo
                                                              age: 11
                                                            
                                                            Blog:
                                                              info: learn note
                                                              <<: *author
                                                            
                                                            Artile:
                                                              info: sth just like
                                                              <<: *author
                                                            • 1
                                                            • 2
                                                            • 3
                                                            • 4
                                                            • 5
                                                            • 6
                                                            • 7
                                                            • 8
                                                            • 9
                                                            • 10

                                                            在 JavaScript 中:

                                                            { Author: { name: 'ryo', age: 11 },
                                                              Blog: { info: 'learn note', name: 'ryo', age: 11 },
                                                              Artile: { info: 'sth just like', name: 'ryo', age: 11 } }
                                                            • 1
                                                            • 2
                                                            声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/308112
                                                            推荐阅读
                                                            相关标签
                                                              

                                                            闽ICP备14008679号