我想要一个简单的教程来向我展示如何加载 yaml 文件并解析数据。 外籍人士风格会很棒,但任何实际以某种形式向我显示数据的解决方案都会很有用。
到目前为止,我在 C 的 yaml-0.1.1
源代码中运行了多次测试,要么出现错误,没有任何输出,要么在 run-emitter.c
中运行案件。 它读取 yaml 文件并将其打印到 STDOUT,它不会通过 libyaml 函数/结构生成文本。 在出现错误的情况下,我不知道是否是因为文件损坏或我的构建不正确(我没有修改任何内容...)该文件是从 yaml.org 复制的
任何人都可以给我指一个教程? (我用 google 搜索了至少 30 分钟,阅读了任何看起来相关的内容)或者有一个很好的教程或示例的库的名称。 也许您可以告诉我哪个 libyaml
测试会加载到文件中并对其执行某些操作,或者为什么会出现错误。 本文档不解释如何使用该文件 - 仅解释如何加载它:
http://pyyaml.org/wiki/LibYAML#Documentation
I want a simple tutorial to show me how to load a yaml file and parse the data. Expat style would be great but any solution that actually shows me the data in some form would be useful.
So far I ran multiple tests in the yaml-0.1.1
source code for C and I either get an error, no output whatsoever, or in the run-emitter.c
case. It reads in the yaml file and prints it to STDOUT
, it does not produce the text via libyaml
functions/structs. In the cases with an error I don't know if it was because the file was bad or my build is incorrect (I didn't modify anything...) The file was copied from yaml.org
Can anyone point me to a tutorial? (I googled for at least 30 minutes reading anything that looked relevant) or a name of a lib that has a good tutorial or example. Maybe you can tell me which libyaml
test loads in files and does something with it or why I got errors. This document does not explain how to use the file--only how to load it:
http://pyyaml.org/wiki/LibYAML#Documentation
发布评论
评论(5)
尝试 yaml-cpp (按照 这个问题)适用于 C++ 解析器。
披露:我是作者。
示例语法(来自 教程):
Try yaml-cpp (as suggested by this question) for a C++ parser.
Disclosure: I'm the author.
Example syntax (from the Tutorial):
我在以下位置写了一篇教程
http://wpsoftware.net/andrew/pages/libyaml.html。
这涵盖了在 C 中使用 libyaml 的基础知识,使用基于标记和基于事件的解析。 它包括用于输出 YAML 文件内容的示例代码。
I have written a tutorial at
http://wpsoftware.net/andrew/pages/libyaml.html.
This covers the basics of using libyaml in C, using token-based and event-based parsing. It includes sample code for outputting the contents of a YAML file.
C 示例 - 将 YAML 树解析为 glib "N-ary树”:
C example - parsing YAML tree to a glib "N-ary tree":
作为 yaml-cpp 和 libyaml 的替代品,有 rapidyaml< /a>. 这是一个例子。
config.yaml
更新
请注意,该项目递归地使用子模块,这就是 GitHub 上的“下载 ZIP”选项不起作用的原因。 使用 git
考虑到您已经在 thirdparty/rapidyaml 中克隆了
rapidyaml
,这里是一个最小的 cmake 配置。CMakeLists.txt
As an alternative to
yaml-cpp
andlibyaml
there is rapidyaml. Here's an example.config.yaml
Update
Be aware that this project uses submodules recursively, that is why "Download ZIP" option on GitHub will not work. Use git
Considering you have
rapidyaml
cloned in thirdparty/rapidyaml here is a minimal cmake configuration .CMakeLists.txt
“yaml load lang:c++”的 Google 代码搜索(现已失效)将其作为第一个链接:demo.cc:
A Google Code Search (now defunct) for "yaml load lang:c++" gave this as the first link: demo.cc: