I made a yaml file as shown below.
Define1: &Define1
0: zero
1: one
Define2:
<<: *Define1
2: two
And I tried the YAML Online Parser . The result is as follows. (Just get how the nodes are built.)
{
"Define1": {
"0": "zero",
"1": "one"
},
"Define2": {
"0": "zero",
"1": "one",
"2": "two"
}
}
Of course, I expected yaml-cpp to be parsed the same way, but it is somehow different.
I think so. (Almost sure)
{
"Define1": {
"0": "zero",
"1": "one"
},
"Define2": {
"Define1": {
"0": "zero",
"1": "one"
},
"2": "two"
}
}
What the heck! Then, do I need to check the type of node during the loop?
Is this a known issue? or are yaml-cpp just parsing this path?
This code did just that.
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;
}
source
share