boost-propertytree

C++: How to create an array using boost::property_tree?

徘徊边缘 提交于 2019-12-18 12:16:22
问题 I don't see a way to create an array using boost::property tree. The following code ... #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/json_parser.hpp> #include <iostream> int main() { try { boost::property_tree::ptree props; props.push_back(std::make_pair("foo", "bar")); props.push_back(std::make_pair("foo", "baz")); boost::property_tree::write_json("prob.json", props); } catch (const std::exception & ex) { std::cout << ex.what() << std::endl; } } ... just gives me ..

Serializing and deserializing JSON with Boost

自闭症网瘾萝莉.ら 提交于 2019-12-17 07:10:11
问题 I'm newbie to C++. What's the easiest way to serialize and deserialize data of type std::Map using boost . I've found some examples with using PropertyTree but they are obscure for me. 回答1: Note that property_tree interprets the keys as paths, e.g. putting the pair "a.b"="z" will create an {"a":{"b":"z"}} JSON, not an {"a.b":"z"}. Otherwise, using property_tree is trivial. Here is a little example. #include <sstream> #include <map> #include <boost/property_tree/ptree.hpp> #include <boost

Boost ptree array of numbers

蓝咒 提交于 2019-12-13 17:24:29
问题 I use the following code to create an array of the numbers. After running the following code, I reveive the following results: { "": "1.100000", "": "2.200000", "": "3.300000" } It is good except for my desired result has to be an array of numbers not string. Adding a number directly by boost::property_tree::ptree(x) gives me an error too. How can I produce my output json results? { "": 1.100000, "": 2.200000, "": 3.300000 } Code: #include <iostream> #include <boost/property_tree/ptree.hpp>

Accessing values using a boost::property_tree::string_path

谁说胖子不能爱 提交于 2019-12-12 21:12:24
问题 I am playing with boost::property_tree::ptree, using namely the following json file: { "menu": { "foo": "true", "bar": "true", "value": "102.3E+06", "popup": [ { "value": "New", "onclick": "CreateNewDoc()" }, { "value": "Open", "onclick": "OpenDoc()" } ] } } I have been trying to access nested "value" with no luck so far, here is what I did: #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/json_parser.hpp> #include <boost/foreach.hpp> int main(int argc, char *argv[]) {

Boost.PropertyTree subpath processing

北城以北 提交于 2019-12-11 11:54:20
问题 The following is a reduced sample of actual xml I would like to process with Boost.PropertyTree library. Actually, there are a lot of other fields in an original xml-file <?xml version="1.0" encoding="UTF-8"?> <foo> <bar> <item> <link>http://www.one.com</link> </item> <item> <link>http://www.two.net</link> </item> <item> <link>http://www.sex.gov</link> </item> ... </bar> </foo> I need to iterate through all link tags. There is an example of the required code. for (auto item: pt.get_child("foo

Serializing std::list into json with boost ptree

我怕爱的太早我们不能终老 提交于 2019-12-11 11:51:30
问题 okay, so I am banging my head on this for last couple of days but still I am unable to get it right. I have a std::list container and I want to serialize it into JSON string so that I can send it over network. NOTE: I compile my code using following: g++ -std=c++11 -o main main.cpp DBAccess11.cpp -lsqlite3 -lboost_serialization I took help of this and this Below is my DBAccess1.h file. #ifndef DBAccess1_HH #define DBAccess1_HH #include <list> // I have deleted some header for sake of

Boost property tree specify allowed values

半世苍凉 提交于 2019-12-11 09:39:44
问题 I wanted to use boosts property tree as handling the settings of my c++ app since it seems to be widely used in this scenario. My question: when changing values in the property tree (through xml parsing or manually), is there a way to specify a list of allowed values of a key in advance? E.g. if I wanted to do a simple "Yes/No" setting, do I have to check the values with an if - condition or can I somehow teach my tree to only accept the two values "Yes" and "No" for the specific key in

Add XML headers using Boost's property trees [duplicate]

雨燕双飞 提交于 2019-12-11 09:37:15
问题 This question already has answers here : Add xml-stylesheet processing instructions to boost property_tree (2 answers) Closed 4 years ago . I've been working on a XML reader/writer, and I used Boost's property trees to do so. Everything is working, only one thing is missing in the output file: I'd like to add two header tags at the top of the file. Right now, the only header is this one, automatically written by Boost's write_xml() function: <?xml version="1.0" encoding="UTF-8" standalone="no

Boost XML parser can support <![CDATA[ … ]]>?

▼魔方 西西 提交于 2019-12-11 05:18:44
问题 I had able to read the XML file using boost and writing the same content to another file . <data> <![CDATA[This is Test]]> <prod name= "p1"/> </data> while writing to another file this would changes to below format. <data> This is Test <prod name= "p1"/> </data> Here unformatted texts like Is missing in the output file. can some one help on how to write the exact as format for unformatted texts like ? 回答1: Boost does not have an XML parser. Boost Property Tree /uses/ an XML parser to...

boost property tree put/get DBL_MAX

人走茶凉 提交于 2019-12-11 03:27:19
问题 I'm programming a ptree and at some point I need to put DBL_MAX in (as a default value). I see the right number when I open the generated xml-file. But when I use ptree.get to get the number an exception is thrown: conversion of data to type "d" failed Here's my code: using boost::property_tree::ptree; ptree pt; double d=-DBL_MAX; double d2=-1.797693134862316e+308; double d3=-1.79769e+308; cout<<d<<endl; cout<<d2<<endl; cout<<d3<<endl; pt.put<double>("double", d); write_xml("test.xml", pt);