boost库之property tree库,解析JSON、XML、INI等

4 篇文章 0 订阅


代码:

#include <iostream>
#include <string>

#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/lexical_cast.hpp>

using namespace std;
using namespace boost;
using namespace boost::property_tree;

int main(int argc, char* argv[])
{
        ptree tree;

        //1. read_json<ptree>()、istringstream
        istringstream iss("{\"KXFR_ID\":123,\"ZONE\":\"ffdns.net\"}");

        read_json<ptree>(iss, tree);

        string kxfr_id = tree.get_child("KXFR_ID").get_value<string>("KXFR_ID");
        string zone = tree.get_child("ZONE").get_value<string>("ZONE");
        cout<<"1. read_json<ptree>:"<<endl<<"kxfr_id:"<<lexical_cast<int>(kxfr_id)<<", zone:"<<zone<<endl<<endl;

        //2. write_json<ptree>()、ostringstream
        ostringstream oss;

        write_json<ptree>(oss, tree);

        cout<<"2. write_json<ptree>:"<<endl<<oss.str()<<endl;

        return 0;
}

输出结果:



参考资料:

        Boost.PropertyTree:http://www.boost.org/doc/libs/1_49_0/doc/html/property_tree.html



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值