1. YAML(Yet Another Markup Language)与XML、JSON的比较
YAML
Peple:
- name: Xiaoming
age: 21
address: Shenzhen, Futian, 518000
XML
<People>
<Person>
<name>Xiaoming</name>
<age>21</age>
<address>Shenzhen, Futian, 518000</address>
</Person>
</People>
JSON
{
"People": {
{
"name": "Xiaoming",
"age": 21,
"adress": Shenzhen, Futian, 518000
}
}
}
2. YAML语法
YAML语法规则中存在与其他(XML、JSON)不同的语法,YAML中使用空格作为缩进标记。
Key-Value Pair
Animal: Lion
Fruit: Apple
Meal: "Tomato Tapas"
# 此处加双引号""是由于Tomato Tapas中存在空格
# 使用" "不会转义字符串中的特殊字符
# 使用' '会转义字符串中的特殊字符
# 在冒号后面加1个空格
Arrays / Lists
Drinks:
- Espresso
- Water
Meals:
- "Tomato Tapas"
- "Seafood Soup"
- Burger
# 两个Array: Drinks、 Meals
# 在-前面加2个空格,在-后面加1个空格
Dictionaries / Maps
Burger:
Calories: 200
Price: 15
Espresso:
Calories: 60
Price: 5
# 两个字典: Burger、Espresso
# 两个字典中分别存在两个属性(Properties): Calories、Price
# 在字典的属性前面加2个空格
Arrays with Dictionaries
Drinks:
- Espresso:
Calories: 60
Price: 5
Meals:
- Burger
Calories: 80
Price: 5
Comment
# 此处使用单#号作为注释的前导符.