首页 > 其他 > 详细

YAML格式的语法

时间:2018-11-07 18:13:14      阅读:222      评论:0      收藏:0      [点我收藏+]

基本格式

  • 用空格缩进, 不能用tab
  • 用#标记注释
  • 列表: 用短划(-)标记元素
  • 映射: 用冒号(:)分隔key, value. 如果写在一行, 需要用逗号分隔并前后加花括号
  • 字符串: 不加引号, 加单引号或者加双引号都可以, 加双引号时可以使用\开头的转义字符
  • 多行字符串可以用 | 或 > 符号, 紧接着换行符
  • 重复的节点, 可以用 & 标识, 并用 * 来引用

基本元素

列表

# 普通
 - Casablanca
 - North by Northwest
 - The Man Who Wasn‘t There

# 单行
[milk, pumpkin pie, eggs, juice]
men: [John Smith, Bill Jones]
women:
  - Mary Smith
  - Susan Williams

 

映射

# Indented Block
   name: John Smith
   age: 33
# Inline Block
 {name: John Smith, age: 33}
- {name: John Smith, age: 33}
- name: Mary Smith
  age: 27

 

多行字符串

data: |
   There once was a short man from Ealing
   Who got on a bus to Darjeeling
       It said on the door
       "Please don‘t spit on the floor"
   So he carefully spat on the ceiling

data: >
   Wrapped text
   will be folded
   into a single
   paragraph

   Blank lines denote
   paragraph breaks

 

指定类型

a: 123                     # an integer
b: "123"                   # a string, disambiguated by quotes
c: 123.0                   # a float
d: !!float 123             # also a float via explicit data type prefixed by (!!)
e: !!str 123               # a string, disambiguated by explicit type
f: !!str Yes               # a string via explicit type
g: Yes                     # a boolean True (yaml1.1), string "Yes" (yaml1.2)
h: Yes we have No bananas  # a string, "Yes" and "No" disambiguated by context.

picture: !!binary |
  R0lGODdhDQAIAIAAAAAAANn
  Z2SwAAAAADQAIAAACF4SDGQ
  ar3xxbJ9p0qa7R0YxwzaFME
  1IAADs=
myObject:  !myClass { name: Joe, age: 15 }

 

YAML格式的语法

原文:https://www.cnblogs.com/milton/p/9924179.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!