英文:
Is it possible to have a object and a list separately in yaml? YAML Syntax Error
问题
我想知道为什么我在以下示例中会得到隐式键必须在一行上
和隐式映射键必须跟随映射值
的错误。在yaml中是否可能分别拥有一个对象和一个列表?
# 这是一条注释
# 这些是键-值对
app: user-auth
port: 22
version: 1.1
# 这是一个对象
microservices:
app: user-auth
port: 22
version: 1.1
# 这是一个列表
- one
- two
- three
我尝试在文件的不同位置添加列表,但都没有成功。如果其余部分被注释掉,它就不会出现错误,所以我想知道为什么会出现这些错误。
英文:
I'm wondering why I get the Implicit keys need to be on a single line
and Implicit map keys need to be followed by map value
errors from the following example. Is it possible to have an object and a list separately in yaml?
# This is a comment
# These are key-value pairs
app: user-auth
port: 22
version: 1.1
# This is an object
microservices:
app: user-auth
port: 22
version: 1.1
# This is a list
- one
- two
- three
I tried adding the list in different positions in the file to no avail. It doesn't give the error if the rest is commented out, so I'm wondering why it gives the errors.
答案1
得分: 0
是的,可以在YAML中分别使用对象和列表。然而,重要的是要使用正确的语法。在这种情况下,您缺少一个冒号(:)。
object:
key1: value1
key2: value2
list:
- item1
- item2
- item3
英文:
Yes, it is possible to have both an object and a list separately in YAML. However, it is important to use the correct syntax. In this case you are missing a colon (:).
object:
key1: value1
key2: value2
list:
- item1
- item2
- item3
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论