YAML – 这两种映射结构之间有什么区别吗?

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

YAML - Is there a difference between these two mapping structures?

问题

我相信以下两种结构是指定映射的等效方式。

environment:
  VARIABLE_1: value1
  VARIABLE_2: value2
environment:
   - VARIABLE_1=value1
   - VARIABLE_2=value2

我相信这两种方式都应该是指定映射的等效方式,以JSON格式表示如下:

{
    "environment" : {
        "VARIABLE_1" : "value1",
        "VARIABLE_2" : "value2"
    } 
}

我的理解是否正确?

因为我不太了解术语,所以无法通过DuckDuckGo或其他搜索引擎来搜索答案。

不过,我确实查看了文档,没有发现明显的信息。

https://yaml.org/spec/1.2.2/

英文:

I believe the following two structures are equivalent ways of specifying a map.

environment:
  VARIABLE_1: value1
  VARIABLE_2: value2
environment:
   - VARIABLE_1=value1
   - VARIABLE_2=value2

I believe both of these should be equivalent ways of specifying a map, which in JSON format would be this:

{
    "environment" : {
        "VARIABLE_1" : "value1",
        "VARIABLE_2" : "value2"
    } 
}

Is my understanding correct?

Because I do not know the terminology in detail I could not perform a search to find an answer via duckduckgo or other search engine.

I did however scan the docs and nothing obvious jumped out at me.

https://yaml.org/spec/1.2.2/

答案1

得分: 1

第一个是类似Python中的字典或Golang中的映射,第二个是类似Python中的列表或Golang中的切片。你的JSON等价于第一个YAML示例。你的第二个YAML示例会类似于以下内容:

{
  "environment": [
    "VARIABLE_1=value1",
    "VARIABLE_2=value2"
  ]
}
英文:

no, first one is a like a dictionary in python or map in golang or ... in ... . second one is a like a list in python or a slice in golang or ... in ... . your json is equivalent version of map(first yaml example). your second yaml example would be something like this:

{
  "environment": [
    "VARIABLE_1=value1",
    "VARIABLE_2=value2"
  ]
}

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

发表评论

匿名网友

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

确定