1

There have been a number of examples posted to the web that demonstrate how to create a JSON array using boost's property tree.

The basic syntax is:

boost::property_tree::ptree array;
array.push_back(std::make_pair("", "value-1"));
array.push_back(std::make_pair("", "value-2"));

This appears to not work using boost 1.54 and visual studio c++ 2012. It works fine using VC 2010 and the same boost version.

The error I receive is "cannot convert parameter 1 from std::pair<_Ty1,_Ty2> to const std::pair<_Ty1,_Ty2> &"

Any suggestions that others may have on getting around this would be greatly appreciated.

1 Answers1

0

ptree::push_back takes a ptree::value_type. Which is not a pair<key, value> but a pair<key, ptree>. push_back() forwards to insert() which copies the given ptree (defined with pair::second) into the current ptree

I would suggest sticking to ptree.add(). See the five minute tutorial, where it does essentially what you're wanting to do with an array of equally named nodes

kornman00
  • 808
  • 10
  • 27