So lets take a look onto a littel bit modified example code:
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <boost/foreach.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
void load(const std::string &file_path)
{
using boost::property_tree::ptree;
ptree pt;
std::ifstream script;
script.open(file_path.c_str());
read_xml(script, pt);
BOOST_FOREACH(boost::property_tree::ptree::value_type &v,
config.get_child("config.servecies"))
{
std::cout
<< "First data: " << v.first.data() << std::endl
<< "Second data: " << v.second.data() << std::endl;
}
}
I try it on with such xml:
<config>
<servecies>
<module>file</module>
<module>Admin</module>
<module>HR</module>
<notModule>MyNotModule</notModule>
</servecies>
</config>
it prints:
First data: module
Second data: file
First data: module
Second data: Admin
First data: module
Second data: HR
First data: notModule
Second data: MyNotModule
But when I try such json file (created from this xml via this web tool):
{
"config": {
"name": "myconfig",
"servecies": {
"module": [
"file",
"Admin",
"HR"
],
"notModule": "MyNotModule"
}
}
}
it prints:
First data: module
Second data:
First data: notModule
Second data: MyNotModule
How to make boost property_tree produce same results on JSON as it parses XML? How to find out if value_type is some sort of one dimentional array and iterate thru it?