# YAML流樣式

YAML中的流樣式可以被認爲是JSON的自然擴展，以覆蓋摺疊內容行以獲得更好的可讀特徵，該特徵使用錨點和別名來創建對象實例。 在本章中，將重點關注以下概念的流表示

• 別名節點
• 空節點
• 流標量樣式
• 流集合樣式
• 流節點

``````%YAML 1.2
---
!!map {
? !!str "First occurrence"
: &A !!str "Foo",
? !!str "Override anchor"
: &B !!str "Bar",
? !!str "Second occurrence"
: *A,
? !!str "Reuse anchor"
: *B,
}``````

``````{
"First occurrence": "Foo",
"Second occurrence": "Foo",
"Override anchor": "Bar",
"Reuse anchor": "Bar"
}``````

``````%YAML 1.2
---
!!map {
? !!str "foo" : !!str "",
? !!str "" : !!str "bar",
}``````

JSON中空節點的輸出如下所示 -

``````{
"": "bar",
"foo": ""
}``````

``````%YAML 1.2
---
!!map {
? !!str "implicit block key"
: !!seq [
!!map {
? !!str "implicit flow key"
: !!str "value",
}
]
}``````

``````{
"implicit block key": [
{
"implicit flow key": "value"
}
]
}``````

YAML中的流集合與另一個流集合中的塊集合嵌套。 流集合條目以逗號(`,`)指示符終止。 以下示例詳細說明了流集合塊 -

``````%YAML 1.2
---
!!seq [
!!seq [
!!str "one",
!!str "two",
],

!!seq [
!!str "three",
!!str "four",
],
]``````

JSON中的流集合輸出如下所示 -

``````[
[
"one",
"two"
],
[
"three",
"four"
]
]``````

``````%YAML 1.2
---
!!seq [
!!seq [ !!str "a", !!str "b" ],
!!map { ? !!str "a" : !!str "b" },
!!str "a",
!!str "b",
!!str "c",]``````

``````[
[
"a",
"b"
],

{
"a": "b"
},

"a",
"b",
"c"
]``````

-