gpt4 book ai didi

yaml - 在YAML属性中指定字符串值 'yes'

转载 作者:行者123 更新时间:2023-12-03 15:36:15 35 4
gpt4 key购买 nike

考虑以下文档:

foo:
bar: Yes

根据 the spec,这应该解释为 Boolean,而不是 String

但是, it seems对此文档产生了相同的解释:
foo:
bar: 'Yes'

如果我误解了,实际上 'Yes'(用引号引起来)应该理解为 String类型的值,我在规范书中的哪里可以找到理由?

但是,如果我没有正确解释,并且这些文档根据规范是等效的,那么如何指定值为 "Yes"的字符串作为YAML属性的值?

最佳答案

这取决于 ;-)

YAML 1.1中, bool 类型定义如下:

A Boolean represents a true/false value. Booleans are formatted as English words (“true”/“false”, “yes”/“no” or “on”/“off”) for readability and may be abbreviated as a single character “y”/“n” or “Y”/“N”.



YAML 1.2中, bool 类型定义如下:

Booleans: [ true, True, false, FALSE ]



通过引号将值 Yes分配给键:
foo: 'Yes'
bar: "Yes"

分配 bool 值并与YAML解析器的 future 版本兼容应使用
foo: false
bar: True

您可以在 https://yamlvalidator.com/上使用YAML语法进行游戏

关于yaml - 在YAML属性中指定字符串值 'yes',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53648244/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com