首页 > 解决方案 > Boost Property tree - 处理一个空的孩子

问题描述

我正在尝试使用 Boost PropertyTree 库将一些信息转储到导出文件中。我已将文档变红,但遇到了一个问题 - 当将空属性树分配为儿子时,它表示为空字符串而不是空字典。在这种情况下,我尝试使用一种解决方法并返回一个 empty_ptree,但这没有帮助。任何建议将不胜感激。

Code :
//path = pwd
ptree main;
ptree test1;   
ptree test2;   
test1.put("key", "value")
main.put_child("test1_key", test1);
main.put_child("test2_key", test2);
write_json(path, main)

result :
{
    "test1": {
        "key": "value"
    },
    "test2": ""  //bad - expected it to be a dictionary as well.
}

expected :
result :
{
    "test1": {
        "key": "value"
    },
    "test2": {}
}

标签: c++jsonboost

解决方案


推荐阅读