📜  YAML-序列样式

📅  最后修改于: 2020-10-14 08:43:46             🧑  作者: Mango


要了解序列样式,了解集合很重要。集合和序列样式的概念并行工作。 YAML中的集合用适当的序列样式表示。如果要引用标签的正确顺序,请始终引用集合。 YAML中的集合由数组中表示的从零开始的连续整数索引。序列样式的重点始于集合。

让我们将宇宙中行星的数量视为可以作为一个集合创建的序列。以下代码显示了如何表示宇宙中行星的序列样式-

# Ordered sequence of nodes in YAML STRUCTURE
Block style: !!seq
- Mercury   # Rotates - no light/dark sides.
- Venus     # Deadliest. Aptly named.
- Earth     # Mostly dirt.
- Mars      # Seems empty.
- Jupiter   # The king.
- Saturn    # Pretty.
- Uranus    # Where the sun hardly shines.
- Neptune   # Boring. No rings.
- Pluto     # You call this a planet?
Flow style: !!seq [ Mercury, Venus, Earth, Mars,      # Rocks
                    Jupiter, Saturn, Uranus, Neptune, # Gas
                    Pluto ]                           # Overrated

然后,您可以看到以下以JSON格式显示的有序序列的输出-

{
   "Flow style": [
      "Mercury", 
      "Venus", 
      "Earth", 
      "Mars", 
      "Jupiter", 
      "Saturn", 
      "Uranus", 
      "Neptune", 
      "Pluto"
   ], 
   
   "Block style": [
      "Mercury", 
      "Venus", 
      "Earth", 
      "Mars", 
      "Jupiter", 
      "Saturn", 
      "Uranus", 
      "Neptune", 
      "Pluto"
   ]
}