1

I am facing a problem with the new syntax. When parsing the following yaml file:

S1:
    data_type: spr
    guid: 1 
S2:
    data_type: spr
    guid: 2

using the following code:

#include "yaml.h"
int main () {
    YAML::Node testNode = YAML::LoadFile("data/Sprites.yaml");

    std::cout<<"type "<<testNode["S1"]["data_type"].as<std::string>()<<std::endl;
    std::cout<<"type "<<testNode[1]["data_type"].as<std::string>()<<std::endl;
    return 0;
}

The first line works and outputs "type spr", while the second line doesn't, throwing a YAML::TypedBadConversion < std::string >.

Shouldn't them both have the same output? Or does numbered indexes work only on sequences and not on maps? What am I doing wrong?

4

1 回答 1

0

在 YAML 中,地图没有顺序,因此要求地图的“第一个条目”是没有意义的。相反,使用不存在testNode[1]的 key 引用映射的条目。1

于 2014-02-16T23:34:50.273 回答