I want to print the json array using below code snippet but it is not giving the desired result . Here is the output
{
"prefix": "standard",
"faceID": "42"
}
{
"prefix1": "standard2",
"faceID2": "44"
}
This is produced by below code snippet:
#include <boost/serialization/string.hpp>
#include <string>
#include <sstream>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
using boost::property_tree::ptree;
using boost::property_tree::write_json;
void create_array(ptree parent)
{
std::stringstream oss;
write_json(oss,parent);
std::string serialized_strings(oss.str());
std::cout << oss.str() << std::endl;
}
int main()
{
ptree pt,pt1;
pt.put("prefix","standard");
pt.put("faceID",42);
create_array(pt);
pt1.put("prefix1","standard2");
pt1.put("faceID2",44);
create_array(pt1);
}
expected output:
[
{
"prefix": "standard",
"faceID": "42"
},
{
"prefix1": "standard2",
"faceID2": "44"
}
]