在YAML中,可以将对象和列表分开吗?YAML语法错误。

huangapple go评论133阅读模式
英文:

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


huangapple
  • 本文由 发表于 2023年3月7日 09:05:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/75657200.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定