yaml解析的方式? (yaml-cpp)
我制作了一个如下所示的 yaml 文件。
Define1: &Define1
0: zero
1: one
Define2:
<<: *Define1
2: two
并在 在线 YAML 解析器中进行了尝试。结果如下。 (只需了解节点的构造方式即可。)
{
"Define1": {
"0": "zero",
"1": "one"
},
"Define2": {
"0": "zero",
"1": "one",
"2": "two"
}
}
当然,我期望“yaml-cpp”会以相同的方式解析,但它在某种程度上有所不同。
我想是这样的。 (几乎可以肯定)
{
"Define1": {
"0": "zero",
"1": "one"
},
"Define2": {
"Define1": {
"0": "zero",
"1": "one"
},
"2": "two"
}
}
什么鬼!那么我必须在循环时检查节点类型吗?
这是一个已知问题吗?或者'yaml-cpp'只是这样解析?
这段代码就是我的做法。
// already parsed
const YAML::Node& node = &(docYAML)["Define2"];
for (YAML::Iterator it=node->begin(); it!=node->end(); ++it)
{
const YAML::Node& nodeList = it.second();
std::string str;
nodeList[0] >> str;
}
I've made a yaml file like below.
Define1: &Define1
0: zero
1: one
Define2:
<<: *Define1
2: two
And tried in Online YAML parser. The result is like below. ( Just get how nodes are constructed. )
{
"Define1": {
"0": "zero",
"1": "one"
},
"Define2": {
"0": "zero",
"1": "one",
"2": "two"
}
}
Of course I expected 'yaml-cpp' would parse same way but it's somehow different.
I guess it's like this. (Almost sure)
{
"Define1": {
"0": "zero",
"1": "one"
},
"Define2": {
"Define1": {
"0": "zero",
"1": "one"
},
"2": "two"
}
}
What the hell! Then do I have to check node type while looping?
Is this a known issue? or 'yaml-cpp' just parse that way?
This code is how I did.
// already parsed
const YAML::Node& node = &(docYAML)["Define2"];
for (YAML::Iterator it=node->begin(); it!=node->end(); ++it)
{
const YAML::Node& nodeList = it.second();
std::string str;
nodeList[0] >> str;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
yaml-cpp 尚未实现“合并”键。如果您想跟踪该问题直至其实施,请参阅 http:// /code.google.com/p/yaml-cpp/issues/detail?id=41。
目前,yaml-cpp 实际上将您的 YAML 文件解析为:
yaml-cpp doesn't implement the "merge" key yet. If you want to follow the issue until it's implemented, see http://code.google.com/p/yaml-cpp/issues/detail?id=41.
For now, yaml-cpp is actually parsing your YAML file as: