YAML - 塊標量頭



在本章中,我們將重點介紹用於表示內容的不同標量型別。在 YAML 中,註釋可以位於標量內容之前或之後。請務必注意,不應將註釋包含在標量內容中。

請注意,除了在多個鍵中使用外,所有流式標量樣式都可以包含多行。

標量的表示如下 −

%YAML 1.1
---
!!map {
   ? !!str "simple key"
   : !!map {
      ? !!str "also simple"
      : !!str "value",
      ? !!str "not a simple key"
      : !!str "any value"
   }
}

塊標量頭部的生成輸出如下 −

{
   "simple key": {
      "not a simple key": "any value", 
      "also simple": "value"
   }
}

文件標記標量內容

此示例中的所有字元都被視為內容,包括內部空格字元。

%YAML 1.1
---
!!map {
   ? !!str "---"
   : !!str "foo",
   ? !!str "...",
   : !!str "bar"
}

%YAML 1.1
---
!!seq [
   !!str "---",
   !!str "...",
   !!map {
      ? !!str "---"
      : !!str "..."
   }
]

純換行符以以下示例表示 −

%YAML 1.1
---
!!str "as space \
trimmed\n\
specific\L\n\
none"

相同的相應 JSON 輸出如下 −

"as space trimmed\nspecific\u2028\nnone"
廣告