#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<