YAML教程@第七章 YAML流程

版权声明:忠于祖国,忠于人民 https://blog.csdn.net/boss2967/article/details/89556447

YAML遵守流程的标准程序。YAML中的本机数据结构包括简单表示。
YAML中的信息处理以两种方式使用,机器处理和人类消费。YAML中处理器在给定应用搞程序中必须提供信息结构。

YAML包括用于以串行格式标识数据对象的序列化过程。YAML信息的处理包括三个阶段:表示,序列化,表示和解析。

表示

YAML表示使用三种节点的数据结构:序列,映射,和标量。

序列

序列是指有序的条目数,他映射键值对的无序关联。他对应per或者python数组列表。

product:
   - sku         : BL394D
     quantity    : 4
     description : Football
     price       : 450.00
   - sku         : BL4438H
     quantity    : 1
     description : Super Hoop
     price       : 2392.00
映射

映射表示字典数据结构或者哈希表。

batchLimit: 1000
threadCountLimit: 2
key: value
keyMapping: <What goes here?>
标量

表示字符串,整数,日期和原子数据类型的标准值。YAML还包括指定数据类型结构的节点

序列化

YAML中需要序列化过程,序列化的结果就是YAML序列化树,可以遍历他以产生一些列YAML数据的时间调用。

consumer:
   class: 'AppBundle\Entity\consumer'
   attributes:
      filters: ['customer.search', 'customer.order', 'customer.boolean']
   collectionOperations:
      get:
         method: 'GET'
         normalization_context:
       groups: ['customer_list']
   itemOperations:
      get:
         method: 'GET'
         normalization_context:
            groups: ['customer_get']
表示

YAML序列化的最终输出称为表示。他以人类友好的方式表示字符流。
YAML处理器包括创建流处理缩进和格式化内容的各种演示细节。
YAML表示过程就是一个示例创建JSON值的结果。

{
   "consumer": {
      "class": "AppBundle\\Entity\\consumer",
      "attributes": {
         "filters": [
            "customer.search",
            "customer.order",
            "customer.boolean"
         ]
      },
      "collectionOperations": {
         "get": {
            "method": "GET",
            "normalization_context": {
               "groups": [
                  "customer_list"
               ]
            }
         }
      },
      "itemOperations": {
         "get": {
            "method": "GET",
            "normalization_context": {
               "groups": [
                  "customer_get"
               ]
            }
         }
      }
   }
}
解析

解析是呈现的逆过程,他包含一个字符流并创建一系列事件。他会丢弃导致序列化事件的演示过程中的详细信息。由于输入不良,解析过程可能会失败。他基本上是一个检查YAML是否是一个合格的程序。

---
   environment: production
   classes:
      nfs::server:
         exports:
            - /srv/share1
            - /srv/share3
   parameters:
      paramter1

使用三个连字符,它表示文档的开头,后面定义了各种属性。

猜你喜欢

转载自blog.csdn.net/boss2967/article/details/89556447