YAML - 序列样式
要理解序列样式,了解集合非常重要。集合和序列样式的概念是并行工作的。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" ] }