YAML - 標量和標記



YAML 中的標量採用塊狀格式編寫,使用文字型別,表示為 (|)。它表示換行符計數。在 YAML 中,標量採用摺疊風格 (>) 編寫,其中每一行表示結束於 空行更多縮排 行的摺疊空間。

如下所示,新行保留在文字中 −

ASCII Art
--- |
\//||\/||
// || ||__

如下所示,摺疊新行保留用於 更多縮排 行和 空行

>
Sammy Sosa completed another
fine season with great stats.
63 Home Runs
0.288 Batting Average
What a year!

YAML 流式標量包括簡單風格和帶引號風格。帶雙引號的風格包含各種轉義序列。流式標量可以包含多行;換行符始終以這種結構摺疊。

plain:
This unquoted scalar
spans many lines.
quoted: "So does this
quoted scalar.\n"

在 YAML 中,使用特定應用程式型別指定未標記的節點。標記規範的示例通常對 YAML 標記儲存庫使用 seq、mapstr 型別。標記表示為示例,如下所述 −

整數標記

這些標記包含其中的整數值。它們也稱為數字標記。

canonical: 12345
decimal: +12,345
sexagecimal: 3:25:45
octal: 014
hexadecimal: 0xC

浮點數

這些標記包括十進位制值和指數值。它們也稱為指數標記。

canonical: 1.23015e+3
exponential: 12.3015e+02
sexagecimal: 20:30.15
fixed: 1,230.15
negative infinity: -.inf
not a number: .NaN

其他標記

包括嵌入其中的各種整數、浮點數和字串值。因此,被稱為其他標記。

null: ~
true: y
false: n
string: '12345'
廣告