这是有效的 YAML 吗?

发布于 2024-07-05 14:26:01 字数 302 浏览 10 评论 0原文

因此,对于我在 C# 中的文本解析 问题,我直接针对 YAML 。 我在推荐这个库时遇到了困难,所以这是一个快速的方法。

heading:
 name: A name
 taco: Yes
 age: 32

heading:
 name: Another name
 taco: No
 age: 27

等等。 这有效吗?

So for my text parsing in C# question, I got directed at YAML. I'm hitting a wall with this library I was recommended, so this is a quickie.

heading:
 name: A name
 taco: Yes
 age: 32

heading:
 name: Another name
 taco: No
 age: 27

And so on. Is that valid?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

浮生面具三千个 2024-07-12 14:26:01

似乎有一个名为 Kwalify 的 YAML 验证器,它应该会给你答案。 你应该直接使用字符串标记化,伙计。 编写解析器很有趣:)

There appears to be a YAML validator called Kwalify which should give you the answer. You shoulda just gone with the String tokenizing, man. Writing parsers is fun :)

爱人如己 2024-07-12 14:26:01

另一个用于 .NET 的 YAML 库正在开发中。 现在它支持读取 YAML 流。 它已经在 Windows 和 Mono 上进行了测试。 目前正在实施写入支持。

There is another YAML library for .NET which is under development. Right now it supports reading YAML streams. It has been tested on Windows and Mono. Write support is currently being implemented.

空宴 2024-07-12 14:26:01

CodeProject 有一个位于:

http://www.codeproject.com/KB/recipes/yamlparser .aspx

我没有尝试太多,但值得一看。

CodeProject has one at:

http://www.codeproject.com/KB/recipes/yamlparser.aspx

I haven't tried it too much, but it's worth a look.

⊕婉儿 2024-07-12 14:26:01

只是对此做出明确的评论:您有重复的映射键问题。 YAML 处理器会将其解析为 !!map,这会禁止重复的键。 不过,并非所有处理器都强制执行此约束,因此如果将不正确的 YAML 流传递给处理器,您可能会得到不正确的结果。

Just to make an explicit comment about it: You have a duplicate mapping key issue. A YAML processor will resolve this as a !!map, which prohibits duplicate keys. Not all processors enforce this constraint, though, so you might get an incorrect result if you pass an incorrect YAML stream to a processor.

倾`听者〃 2024-07-12 14:26:01

尝试这个(在线 YAML 解析器)

您无需下载任何内容或执行任何操作。 只要去那里,复制并复制即可。 粘贴。 就是这样。

Try this(Online YAML parser).

You don't have to download anything or do something. Just go there, and copy & paste. That's it.

薄凉少年不暖心 2024-07-12 14:26:01

好吧,看来 YAML 已经被淘汰了。 我想要一些人类可写和可读的东西。 另外,这个 C# 实现...我不知道它是否有效,该文档由一些单行代码示例组成。 它对自己的 YAML 文件感到厌烦,是一个老学生项目。 我发现的唯一一个使用 MS-PL 的 C# YAML 解析器,我使用起来不太舒服。

我可能最终会推出自己的格式。 该死的最佳实践,我想做的就是将键与值关联起来。

Well, it appears YAML is gone out the window then. I want something both human writable and readable. Plus, this C# implementation...I have no idea if it's working or not, the documentation consists of a few one line code examples. It barfs on their own YAML files, and is an old student project. The only other C# YAML parser I've found uses the MS-PL which I'm not really comfortable using.

I might just end up rolling my own format. Best practices be damned, all I want to do is associate a key with a value.

海未深 2024-07-12 14:26:01

部分地。 YAML 支持多个连续“文档”的概念。 如果这就是您在这里尝试执行的操作,那么是的,这是正确的 - 您有两个文档(或文档片段)。 为了使其更明确,您应该用三个破折号将它们分开,如下所示:

---
heading:
 name: A name
 taco: Yes
 age: 32
---
heading:
 name: Another name
 taco: No
 age: 27

另一方面,如果您希望使它们成为同一文档的一部分(以便反序列化它们将产生一个包含两个元素的列表),您应该编写就像下面这样。 对缩进级别要格外小心:

- heading:
  name: A name
  taco: Yes
  age: 32
- heading:
  name: Another name
  taco: No
  age: 27

一般来说,YAML 是简洁且人类可读/可编辑的,但不是真正人类可写的,因此您应该始终使用库来生成它。 另外,请注意不同版本的 YAML 之间存在一些重大更改,如果您使用符合不同版本标准的不同语言的库,这些更改可能会影响您。

Partially. YAML supports the notion of multiple consecutive "documents". If this is what you are trying to do here, then yes, it is correct - you have two documents (or document fragments). To make it more explicit, you should separate them with three dashes, like this:

---
heading:
 name: A name
 taco: Yes
 age: 32
---
heading:
 name: Another name
 taco: No
 age: 27

On the other hand if you wish to make them part of the same document (so that deserializing them would result in a list with two elements), you should write it like the following. Take extra care with the indentation level:

- heading:
  name: A name
  taco: Yes
  age: 32
- heading:
  name: Another name
  taco: No
  age: 27

In general YAML is concise and human readable / editable, but not really human writable, so you should always use libraries to generate it. Also, take care that there exists some breaking changes between different versions of YAML, which can bite you if you are using libraries in different languages which conform to different versions of the standard.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文