什么是 YAML-专门给人类阅读的标记语言

什么是 YAML

YAML 是一个数据序列化语言,方便人类阅读,可用于所有编程语言。
YAML is a human friendly data serialization standard for all programming languages.

应用场景

可以用于 conf 配置
我用 YAML 是配置一个服务器的页面路由

YAML 长什么样子

# 记录一个人的体检信息 
# (键值对)
age: 65         # 年龄
height: 178     # 身高
weight: 147     # 体重

# 记录出门要做的事情 
# (键值对 + 数组列表)
去菜市场买:
  - 豆腐
  - 萝卜
去商店买:
  - 砧板
  - 砂锅

YAML 语法详解

YAML’s block collections use indentation for scope and begin each entry on its own line. Block sequences indicate each entry with a dash and space ( “- ”). Mappings use a colon and space (“: ”) to mark each key: value pair. Comments begin with an octothorpe (also called a “hash”, “sharp”, “pound”, or “number sign” - “#”).

  1. YAML 用缩进来表示层级关系,每行是一个语句。
  2. 块级列表 使用短横线和空格开头,如 "- "
  • C
  • PHP
  • javascript
  1. 键值对 使用分号和空格来隔开键和值,如 "key: value"

C: 系统语言
PHP: 服务器语言
javascript: 网页端语言
```

  1. 注释 以井号开头,如 "# 这是一行注释"

javascript: 网页端语言 #使用 nodejs 也可以写服务器脚本
```

YAML also has flow styles, using explicit indicators rather than indentation to denote scope. The flow sequence is written as a comma separated list within square brackets. In a similar manner, the flow mapping uses curly braces.

  1. 层级关系 除了使用缩进,还能够使用特定符号来表示。
  2. 数组 使用方括号和逗号来表示
- [Sammy Sosa , 63, 0.288]
- [Ken Sosa , 70, 0.302]
  1. 多个键值对 使用花括号的逗号来表示
Mark McGwire: {hr: 65, avg: 0.278}

更多

以上为最常用的 YAML 语法,更复杂的语法请参见 英文官网

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,991评论 19 139
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 46,970评论 6 342
  • 刚刚看了王菲的演唱会的视频,觉得不似许多网友评价的那样差。王菲是以嗓音空灵为特色歌手。我相信现在听她歌曲的...
    似流水一样阅读 1,275评论 0 0
  • DocBlockre 注释插件 效果如下图所示 用户自定义设置
    白小虫阅读 253评论 0 2