ptree

ptree get_value with name including “.”

自闭症网瘾萝莉.ら 提交于 2021-02-04 21:18:13
问题 "A": "1" "A.B": "2" "A.C": "3" How to get the value of A.B if i iterate through the ptree it works. if i try to get value of pt.get_child("A\.B").get_value<std::string>() . i get the following exception terminate called after throwing an instance of boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::property_tree::ptree_bad_path> >' what(): No such node please find the complete code below #include <boost/property_tree/ptree.hpp> #include <boost/property

ptree get_value with name including “.”

半世苍凉 提交于 2021-02-04 21:18:07
问题 "A": "1" "A.B": "2" "A.C": "3" How to get the value of A.B if i iterate through the ptree it works. if i try to get value of pt.get_child("A\.B").get_value<std::string>() . i get the following exception terminate called after throwing an instance of boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::property_tree::ptree_bad_path> >' what(): No such node please find the complete code below #include <boost/property_tree/ptree.hpp> #include <boost/property

Parsing XML's with Boost PTree w/o tags

陌路散爱 提交于 2020-08-09 09:23:07
问题 I would like to know if Boost Ptree allows parsing .xml files without having the attribute tags known. I have an XML file that will regularly be updated with new tags, new data, and even remove certain tags. These regular changes prompted me to look into parsing the file without hardcoding the attribute name. Is there any way I can read all the data in the XML file without stating the tag name? Any help is appreciated! 回答1: Ptrees aren't ideal for parsing XML but Boost is so integrated into

Access to specific index in ptree array

末鹿安然 提交于 2019-12-24 11:41:52
问题 I am using boost library to manipulate a JSON file and I would like to access to a specific index of an array in this JSON. boost::property_tree::ptree& jsonfile; const boost::property_tree::ptree& array = jsonfile.get_child("my_array"); What I would like to do is accessing to the value stored at index : // This code does not compile int value = array[index].get < int > ("property"); 回答1: Just code it using the iterators: template <typename T = std::string> T element_at(ptree const& pt, std:

boost ptree access first element with no path name

一笑奈何 提交于 2019-12-24 10:07:15
问题 I am using boost library to manipulate a JSON string and I would like to access to a first element. I was wondering if there where some convenient way to access a first element of ptree with no path name. I do this, but I got no value : namespace pt = boost::property_tree; pt::ptree pt2; string json = "\"ok\""; istringstream is(json); try { pt::read_json(is, pt2); cout << pt2.get_child("").equal_range("").first->first.data() << endl; } catch (std::exception const& e) { cerr << e.what() <<

Iterate through multilevel boost tree

人走茶凉 提交于 2019-12-22 17:37:32
问题 With my tree looking like this: { "Library": { "L_ID": "1", "Book": { "B_ID": "1", "Title": "Moby Dick" }, "Book": { "B_ID": "2", "Title": "Jurassic Park" } }, "Library": { "L_ID": "2", "Book": { "B_ID": "1", "Title": "Velocity" }, "Book": { "B_ID": "2", "Title": "Creeper" } } } What i am looking to do is iterate through the libraries. When i find the L_ID that i am looking for, iterate through the books until i find the B_ID i'm looking for. At that point, i'd like to access all the leaves

How can I parse JSON arrays with C++ Boost?

亡梦爱人 提交于 2019-12-20 09:38:03
问题 I have a file containing some JSON content that looks like: { "frame": { "id": "0", "points": [ [ "0.883", "0.553", "0" ], [ "0.441", "0.889", "0" ], ] }, "frame": ... } How do I parse the values of the double array using C++ and Boost ptree? 回答1: Use the iterators, Luke. First , you have to parse the file: boost::property_tree::ptree doc; boost::property_tree::read_json("input_file.json", doc); ... now, because it seems you have multiple "frame" keys in the top level dictionary you must

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>

How can I parse JSON arrays with C++ Boost?

北战南征 提交于 2019-12-02 19:26:14
I have a file containing some JSON content that looks like: { "frame": { "id": "0", "points": [ [ "0.883", "0.553", "0" ], [ "0.441", "0.889", "0" ], ] }, "frame": ... } How do I parse the values of the double array using C++ and Boost ptree? Use the iterators, Luke. First , you have to parse the file: boost::property_tree::ptree doc; boost::property_tree::read_json("input_file.json", doc); ... now, because it seems you have multiple "frame" keys in the top level dictionary you must iterate over them: BOOST_FOREACH (boost::property_tree::ptree::value_type& framePair, doc) { // Now framePair

C++: boost ptree relative key

巧了我就是萌 提交于 2019-11-30 09:41:40
问题 In C++ using ptree from boost , I need to find the relative key to access a.b.c2.e1 from a.b . This key is c2.e1 . How can I write a function which finds this relative key? #include <iostream> #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/json_parser.hpp> using namespace boost::property_tree; std::string relative_key(const ptree &p1,const ptree &p2) { ?????????????? // return "b.c2.e1"; } int main() { ptree pt0; pt0.put("a.b.c1",4); pt0.put("a.b.c2.e1",4); pt0.put("a