boost-propertytree

How to convert class object to json string using boost library in C++?

筅森魡賤 提交于 2019-12-05 15:01:29
I am fairly new to C++ and I apologise beforehand if you find this very easy. I have the following files POST1.h #ifndef POST1_HH #define POST1_HH #include <iostream> #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/json_parser.hpp> using namespace std ; using boost::property_tree::ptree; using boost::property_tree::read_json; using boost::property_tree::write_json; using boost::property_tree::basic_ptree; #include "DBAccess2.h" class POST1 { public: string TokenNo; string CommandStatus; string CommandID; string CPUID; string ISEncrypted; string JSON_Cmnd_String; void

where is boost property_tree::empty_ptree?

拟墨画扇 提交于 2019-12-05 11:22:54
I'm using boots's property_tree library. I'm looking for a way to get a child node from a ptree object, but return an empty ptree if failed. I came across a nice example in property_tree/examples/empty_ptree_trick.cpp: void process_settings(const std::string &filename) { ptree pt; read_info(filename, pt); const ptree &settings = pt.get_child("settings", empty_ptree<ptree>()); std::cout << "\n Processing " << filename << std::endl; std::cout << " Setting 1 is " << settings.get("setting1", 0) << std::endl; std::cout << " Setting 2 is " << settings.get("setting2", 0.0) << std::endl; std::cout <<

Parsing JSON with boost property tree

一笑奈何 提交于 2019-12-05 02:33:59
I'm building an application that gets movie information from themoviedb.com. The information is provided in a JSON file. I'm trying to store the information using boost property tree. But There is a little problem. I illustrate the problem by the following code: #include <vector> #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/json_parser.hpp> #include <boost/foreach.hpp> using namespace std; using boost::property_tree::ptree; class single_t{ int sID; string sName; public: void setID(int ID){sID=ID;} int getID(){return sID;} void setName(string Name){sName=Name;} string

boost::property_tree : Parsing of Complex xml strucure

孤街醉人 提交于 2019-12-04 21:21:08
I am want to parse below xml structure using boost property_tree. <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Txn ver="1.0"> <TOpts tCount="1" tformat="0" ttimeout="10" /> <TData> <Tvalue date="YYMMDD" time="HHMM" Ref="100"/> </TData> <TCustOpts> <Param name="SALE" value="xyz" /> </TCustOpts> </Txn> I am able to parse, first Topts field of above xml, But for TData & TCustOpts field, I am not getting right iteration and approach to parse the xml and facing exception. Can someone provide me right approach for TData & TCustOpts field parsing. Below is my code for reference.

Disable exception working for boost::smart_ptr but not for boost::property_tree

时光总嘲笑我的痴心妄想 提交于 2019-12-04 19:57:54
I'm using boost 1.57. I need to disable exception support in my not widely-used proprietary compiler. When I needed to use boost::smart_ptr , the following steps worked like a charm: Disabled C++11 support using the following user.hpp file (compiling with -DBOOST_USER_CONFIG="<user.hpp>" ): #define BOOST_HAS_NRVO #define BOOST_NO_COMPLETE_VALUE_INITIALIZATION #define BOOST_NO_CXX11_AUTO_DECLARATIONS #define BOOST_NO_CXX11_AUTO_MULTIDECLARATIONS #define BOOST_NO_CXX11_CHAR16_T #define BOOST_NO_CXX11_CHAR32_T #define BOOST_NO_CXX11_CONSTEXPR #define BOOST_NO_CXX11_DECLTYPE #define BOOST_NO_CXX11

boost::property_tree::json_parser and two-byte wide characters

对着背影说爱祢 提交于 2019-12-04 10:52:22
问题 Introduction std::string text = "á"; "á" is two-byte character (assuming a UTF-8 encoding). So following line prints 2. std::cout << text.size() << "\n"; But std::cout still prints text correctly. std::cout << text << "\n"; My problem I pass text to boost::property_tree::ptree and then to write_json boost::property_tree::ptree root; root.put<std::string>("text", text); std::stringstream ss; boost::property_tree::json_parser::write_json(ss, root); std::cout << ss.str() << "\n"; The result is {

boost::property_tree::info_parser breaks on spaces in value

点点圈 提交于 2019-12-04 04:42:52
问题 I am facing an issue where I have a configuration file and I parse it with boost::property_tree:info_parser. I use this code to do the work: struct _Config { std::string info[2]; boost::property_tree::ptree pt; _Config() { //check if config file exists, if not create it, etc, do other stuff not related to the issue //this code reproduces the issue //DEFAULT VALUE, can be changed by configuration later info[0] = "If updating this file make sure to update all settings accordingly."; info[1] =

no end of line in boost property tree xml writer output

旧时模样 提交于 2019-12-04 03:49:23
Consider the following code using boost::property_tree: #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/xml_parser.hpp> using namespace boost::property_tree; int main() { ptree model_tree; model_tree.add("calibrated", "true"); model_tree.add("model.<xmlattr>.label", "label"); model_tree.add("model.activity.<xmlattr>.type", "fixed"); write_xml("test.xml", model_tree); } By compiling and executing the program I get the following output: <?xml version="1.0" encoding="utf-8"?> <calibrated>true</calibrated><model label="label"><activity type="fixed"/></model> Which is not

Boost read_json and C++11

故事扮演 提交于 2019-12-04 03:11:27
I'm trying to parse JSON using Boost's property_tree parser and from C++11 code (my system is Debian Wheezy with gcc 4.7.2 and Boost 1.49). I tried the following code based on Serializing and deserializing json with boost : #include <map> #include <sstream> #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/json_parser.hpp> using boost::property_tree::ptree; using boost::property_tree::read_json; using boost::property_tree::write_json; void example() { // Write json. ptree pt; pt.put ("foo", "bar"); std::ostringstream buf; write_json (buf, pt, false); std::string json = buf

Using boost property tree to read int array

最后都变了- 提交于 2019-12-03 19:07:23
问题 I have some JSON with a handful of integer array variables, like so: {"a": [8, 6, 2], "b": [2, 2, 1]} I would like to use boost property_tree, for instance: std::stringstream ss; boost::property_tree::ptree pt; ss << "{\"a\": [8, 6, 2], \"b\": [2, 2, 1]}"; boost::property_tree::read_json(ss, pt); std::vector<int> a = pt.get<std::vector<int> >("a"); This doesn't work, nor does any variation on an int pointer that I've tried. How may I read an array from a property tree? 回答1: JSON support, is