鉴于此 yaml:
{CR: {cmd: fade, color: blue, panel: 0, value: 30, fout: 0.5, fint: 5},OL: {cmd: text, value: Blu at 30% on all, color: white, time: 5, position: [540,100], size: 50}}
使用此代码:
bool SEMTools::decodeYaml(QString yaml)
{
try
{
YAML::Node root = YAML::Load(yaml.toStdString().c_str());
YAML::Node::iterator i;
for (i = root.begin(); i != root.end(); i++)
{
qDebug() << (*i).first.as<QString>();
}
return true;
}
catch (YAML::TypedBadConversion<QString> const &e)
{
qDebug() << e.what();
}
return false;
}
我能够检索主键:CR
和OL
. 对于每一个我还需要检索整个对象:
CR: {cmd: fade, color: blue, panel: 0, value: 30, fout: 0.5, fint: 5}
和
OL: {cmd: text, value: Blu at 30% on all, color: white, time: 5, position: [540,100], size: 50}
我试过:
qDebug() << (*i).as<QString>();
但我的应用程序因此错误而崩溃:
terminate called after throwing an instance of 'YAML::InvalidNode'
what(): invalid node; this may result from using a map iterator as a sequence iterator, or vice-versa
获取上述字符串的正确语法是什么?