Boost PropertyTree 解析 JSON 并检测空节点的类型

问题描述

有什么办法可以找出空JSON节点的类型吗? 请检查下面的代码示例:

#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <string>
#include <sstream>
#include <iostream>

using boost::property_tree::ptree;

int main(int argc,char* argv[])
{
    std::stringstream ss("{\"a\": {},\"b\": [],\"c\": \"\"}");

    ptree pt;
    read_json(ss,pt);

    ptree::const_iterator it = pt.begin();
    while (it != pt.end())
    {
        std::cout
            << "key: " << it->first
            << ",value: " << it->second.get_value<std::string>()
            << ",size: " << it->second.size()
//  ? --->  << ",type: " << object,array or scalar
            << std::endl;
        ++it;
    }

    return 0;

}

输出

key: a,value:,size: 0
key: b,size: 0
key: c,size: 0

PropertyTree 结构是否提供了一些数据或方法

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)