yaml-cpp를 사용하여 구문 분석하려는 테스트 yaml 파일이 있습니다. 나는 그것을 구문 분석은 yaml :: nodeType에 혼란 스럽습니다 : yaml-cpp로 정의되지 않았습니다.
test.yaml
testConfig:
# this points to additional config files to be parsed
includes:
required: "thing1.yaml"
optional: "thing2.yaml"
#some extraneous config information
foo: 42
bar: 394
baz: 8675309
나는 testConfig.Type()
반환 YAML::NodeType::Map
를 얻을. 그리고 이것은 예상되는 행동입니다.
그렇다면 includes.Type()
이 YAML::NodeType::Undefined
을 반환하므로 반복 할 수없는 필수 또는 선택적 값을 가져 오기 위해 포함을 구문 분석하려고합니다. 나는 정말로 yaml과 yaml-cpp에 대해 새로운 것이므로 나에게 잘못된 정보를 알려주는 도움을 주시면 감사하겠습니다.
파싱 코드 :
{includes and other such nonsense}
.
.
.
YAML::Node configRoot = YAML::LoadFile(path.c_str());
if(configRoot.IsNull())
{
SYSTEM_LOG_ERROR("Failed to load the config file: %s.",
path.c_str());
return false;
}
YAML::Node includes = configRoot["includes"];
/* ^^^^^^^^^^^^^^^
* I believe that here lies the issue as includes is undefined and
* therefore I cannot iterate over it.
*/
for(auto it = include.begin(); it != include.end(); ++it)
{
// do some fantastically brilliant CS voodoo!
}
.
.
.
{ more C++ craziness to follow }
해결책 : 나는 내가 필요에 따라 포함 구문 분석 할 수 있도록 불필요한 최상위 configTest
를 제거했습니다.
YAML 파일에서'thingX.yaml'을 따옴표로 묶을 필요가 없습니다. – Anthon
@Anthon 정보를 제공해 주셔서 감사합니다. json에게 익숙한데, 여기에는 거의 모든 것이 필요합니다. – CompSciGuy139