博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
boost解析json
阅读量:6903 次
发布时间:2019-06-27

本文共 1625 字,大约阅读时间需要 5 分钟。

#include 
#include
#include
#include
#include
#include
using namespace std;using namespace boost::property_tree; int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); string s = "{/"age/" : 26,/"study/":{/"language/":{/"one/":/"chinese/",/"two/":/"math/"},/"fee/":500,/"subject/":[{/"one/":/"china/"},{/"one/":/"Eglish/"}]},/"person/":[{/"id/":1,/"name/":/"chen/"},{/"id/":2,/"name/":/"zhang/"}],/"name/" : /"huchao/"}"; string s = "{age : 26,study:{ language:{one:chinese,two:math},fee:500,subject:[{one:china},{one:Eglish}]},person:[{id:1,name:chen},{id:2,name:zhang}],name : huchao}"; ptree pt; stringstream stream(s); //这步不知道为什么要这样 read_json
( stream, pt); pt.put("study.language.one","physics");//修改数据(这步废了好久时间,最后通过读英文资料解决) pt.put("study.fee",600); string s1=pt.get
("age"); cout<
<
("name"); cout<
<
("one"); cout<
<
("fee"); cout<
<
second; //first为空 cout<<"subject="<
("one")<
("conf.theme") <
("conf.clock_style") <
("conf.gui") <
second.data()<<","; // } // cout<
("age",29);// pt_11.put("name","chen"); // pt_12.push_back(make_pair("",pt_11));// pt_12.push_back(make_pair("",pt_11)); // //replace or create child node "data"// pt_1.put_child("data",pt_12); // ostringstream os;// write_json(os,pt_1);// cout<
<

里面的有些还是比较模糊,原理不清

vs提示个错误:pnode.get<int>("x")不存在从 "char [2]" 转换到 "boost::property_tree::string_path<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,boost::property_tree::id_translator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >" 的适当构造函数

查了半天结果可以运行,这VS也有点坑人吧

转载地址:http://vzldl.baihongyu.com/

你可能感兴趣的文章
weixinJSDDK
查看>>
eclipse手动安装svn和maven
查看>>
权限管理 (二) 实现中几个问题
查看>>
安家博客园-准备迁移过往博客-发帖提醒自己-别偷懒别偷懒别偷懒!
查看>>
密码学经典之生日悖论与生日攻击【详解】
查看>>
算法题丨3Sum
查看>>
Android学习笔记33:Intent介绍及Intent在Activity中的使用方法
查看>>
java常用类--与用户互动
查看>>
day40-python多进程多线程-多线程实例和锁
查看>>
关于使用pip安装软件的存储库的问题-python
查看>>
Android Material Design-Getting Started(入门)-(一)
查看>>
CHIL-ORACLE-truncate 语法 清空表数据
查看>>
IE和FireFox下的JS调试工具
查看>>
2018全球最强物联网公司榜单揭晓
查看>>
docker的安装和docket拉取Oracle
查看>>
innobackupex 备份数据搭建 MySQL Slave
查看>>
Linux学习三部曲(之二)
查看>>
C#winform拖动无边框窗体
查看>>
CentOS 6.5安装KVM虚拟化
查看>>
centos6构建XFS文件系统
查看>>