【发布时间】:2014-12-15 12:58:38
【问题描述】:
我一直在寻找这个问题的答案,但是如果之前有人问过这个问题,我找不到任何很抱歉的东西。我有以下 json 文件
{"GuiComponents": [
{
"GuiComponent":
{
"screen": "WindowMain",
"type": "class Robot",
"filename": "robot.mesh",
"blueprint": "Betplacement/Robot.json",
"layer": "0",
"position":
{
"x": "0",
"y": "0"
}
}
},
{
"GuiComponent":
{
"screen": "WindowTop",
"type": "class Robot",
"filename": "robot.mesh",
"blueprint": "Betplacement/Robot.json",
"layer": "0",
"position":
{
"x": "0",
"y": "0"
}
}
}
]
}
现在我想遍历 GuiComponents 中名为 GuiComponent 的所有子节点,并将每个子节点分配给一个 ptree 节点。这样,我可以简单地将 ptree 节点传递给任何想要获取特定 GuiComponent 的数据而无需查看所有其他子节点的人。我找不到使用 get_child 执行此操作的方法,因为它只会引发“No such node GuiComponent”异常。
任何帮助将不胜感激。
谢谢
【问题讨论】:
-
您能否提供一个示例,说明您如何尝试使用
get_child()访问节点? -
我试过 boost::property_tree::ptree child = m_tree.get_child("GuiComponents.GuiComponent") 和 boost::property_tree::ptree child = m_tree.get_child("GuiComponent")。谢谢
标签: c++ json boost boost-propertytree